typescript-virtual-container 1.5.1 → 1.5.3

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 (614) hide show
  1. package/.vscode/settings.json +2 -2
  2. package/README.md +34 -28
  3. package/build.js +22 -0
  4. package/builds/{fortune-nyx-v1.5.1-directbash-k6.1.0.mjs → fortune-nyx-v1.5.3-directbash-k6.1.0.mjs} +187 -191
  5. package/builds/{fortune-nyx-v1.5.1-ssh-nosftp.js → fortune-nyx-v1.5.3-ssh-nosftp.js} +214 -218
  6. package/builds/{fortune-nyx-v1.5.1-ssh.cjs → fortune-nyx-v1.5.3-ssh.cjs} +142 -146
  7. package/builds/fortune-nyx-v1.5.3-web.min.js +17036 -0
  8. package/bun.lock +74 -0
  9. package/dist/Honeypot/index.d.ts +0 -1
  10. package/dist/Honeypot/index.js +0 -1
  11. package/dist/SSHClient/index.d.ts +0 -1
  12. package/dist/SSHClient/index.js +0 -1
  13. package/dist/SSHMimic/exec.d.ts +0 -1
  14. package/dist/SSHMimic/exec.js +0 -1
  15. package/dist/SSHMimic/executor.d.ts +0 -1
  16. package/dist/SSHMimic/executor.js +0 -1
  17. package/dist/SSHMimic/hostKey.d.ts +0 -1
  18. package/dist/SSHMimic/hostKey.js +0 -1
  19. package/dist/SSHMimic/index.d.ts +0 -1
  20. package/dist/SSHMimic/index.js +0 -1
  21. package/dist/SSHMimic/loginBanner.d.ts +0 -1
  22. package/dist/SSHMimic/loginBanner.js +0 -1
  23. package/dist/SSHMimic/loginFormat.d.ts +0 -1
  24. package/dist/SSHMimic/loginFormat.js +0 -1
  25. package/dist/SSHMimic/prompt.d.ts +0 -1
  26. package/dist/SSHMimic/prompt.js +0 -1
  27. package/dist/SSHMimic/sftp.d.ts +0 -1
  28. package/dist/SSHMimic/sftp.js +0 -1
  29. package/dist/VirtualFileSystem/binaryPack.d.ts +0 -1
  30. package/dist/VirtualFileSystem/binaryPack.js +0 -1
  31. package/dist/VirtualFileSystem/index.d.ts +0 -1
  32. package/dist/VirtualFileSystem/index.js +0 -1
  33. package/dist/VirtualFileSystem/internalTypes.d.ts +0 -1
  34. package/dist/VirtualFileSystem/internalTypes.js +0 -1
  35. package/dist/VirtualFileSystem/journal.d.ts +0 -1
  36. package/dist/VirtualFileSystem/journal.js +0 -1
  37. package/dist/VirtualFileSystem/path.d.ts +0 -1
  38. package/dist/VirtualFileSystem/path.js +0 -1
  39. package/dist/VirtualPackageManager/index.d.ts +0 -1
  40. package/dist/VirtualPackageManager/index.js +3 -14
  41. package/dist/VirtualShell/idleManager.d.ts +0 -1
  42. package/dist/VirtualShell/idleManager.js +0 -1
  43. package/dist/VirtualShell/index.d.ts +3 -2
  44. package/dist/VirtualShell/index.js +4 -2
  45. package/dist/VirtualShell/shell.d.ts +0 -1
  46. package/dist/VirtualShell/shell.js +0 -1
  47. package/dist/VirtualShell/shellParser.d.ts +0 -1
  48. package/dist/VirtualShell/shellParser.js +0 -1
  49. package/dist/VirtualUserManager/index.d.ts +0 -1
  50. package/dist/VirtualUserManager/index.js +0 -1
  51. package/dist/commands/adduser.d.ts +0 -1
  52. package/dist/commands/adduser.js +0 -1
  53. package/dist/commands/alias.d.ts +0 -1
  54. package/dist/commands/alias.js +0 -1
  55. package/dist/commands/apt.d.ts +0 -1
  56. package/dist/commands/apt.js +0 -1
  57. package/dist/commands/awk.d.ts +0 -1
  58. package/dist/commands/awk.js +0 -1
  59. package/dist/commands/base64.d.ts +0 -1
  60. package/dist/commands/base64.js +0 -1
  61. package/dist/commands/cat.d.ts +0 -1
  62. package/dist/commands/cat.js +0 -1
  63. package/dist/commands/cd.d.ts +0 -1
  64. package/dist/commands/cd.js +0 -1
  65. package/dist/commands/chmod.d.ts +0 -1
  66. package/dist/commands/chmod.js +0 -1
  67. package/dist/commands/clear.d.ts +0 -1
  68. package/dist/commands/clear.js +0 -1
  69. package/dist/commands/command-helpers.d.ts +0 -1
  70. package/dist/commands/command-helpers.js +0 -1
  71. package/dist/commands/cp.d.ts +0 -1
  72. package/dist/commands/cp.js +0 -1
  73. package/dist/commands/curl.d.ts +0 -1
  74. package/dist/commands/curl.js +0 -1
  75. package/dist/commands/cut.d.ts +0 -1
  76. package/dist/commands/cut.js +0 -1
  77. package/dist/commands/date.d.ts +0 -1
  78. package/dist/commands/date.js +0 -1
  79. package/dist/commands/declare.d.ts +0 -1
  80. package/dist/commands/declare.js +0 -1
  81. package/dist/commands/deluser.d.ts +0 -1
  82. package/dist/commands/deluser.js +0 -1
  83. package/dist/commands/df.d.ts +0 -1
  84. package/dist/commands/df.js +0 -1
  85. package/dist/commands/diff.d.ts +0 -1
  86. package/dist/commands/diff.js +0 -1
  87. package/dist/commands/dpkg.d.ts +0 -1
  88. package/dist/commands/dpkg.js +0 -1
  89. package/dist/commands/du.d.ts +0 -1
  90. package/dist/commands/du.js +0 -1
  91. package/dist/commands/echo.d.ts +0 -1
  92. package/dist/commands/echo.js +0 -1
  93. package/dist/commands/env.d.ts +0 -1
  94. package/dist/commands/env.js +0 -1
  95. package/dist/commands/exit.d.ts +0 -1
  96. package/dist/commands/exit.js +0 -1
  97. package/dist/commands/export.d.ts +0 -1
  98. package/dist/commands/export.js +0 -1
  99. package/dist/commands/find.d.ts +0 -1
  100. package/dist/commands/find.js +0 -1
  101. package/dist/commands/free.d.ts +0 -1
  102. package/dist/commands/free.js +0 -1
  103. package/dist/commands/grep.d.ts +0 -1
  104. package/dist/commands/grep.js +0 -1
  105. package/dist/commands/groups.d.ts +0 -1
  106. package/dist/commands/groups.js +0 -1
  107. package/dist/commands/gzip.d.ts +0 -1
  108. package/dist/commands/gzip.js +0 -1
  109. package/dist/commands/head.d.ts +0 -1
  110. package/dist/commands/head.js +0 -1
  111. package/dist/commands/help.d.ts +0 -1
  112. package/dist/commands/help.js +0 -1
  113. package/dist/commands/helpers.d.ts +0 -1
  114. package/dist/commands/helpers.js +0 -1
  115. package/dist/commands/history.d.ts +0 -1
  116. package/dist/commands/history.js +0 -1
  117. package/dist/commands/hostname.d.ts +0 -1
  118. package/dist/commands/hostname.js +0 -1
  119. package/dist/commands/htop.d.ts +0 -1
  120. package/dist/commands/htop.js +0 -1
  121. package/dist/commands/id.d.ts +0 -1
  122. package/dist/commands/id.js +0 -1
  123. package/dist/commands/index.d.ts +0 -1
  124. package/dist/commands/index.js +0 -1
  125. package/dist/commands/kill.d.ts +0 -1
  126. package/dist/commands/kill.js +0 -1
  127. package/dist/commands/ln.d.ts +0 -1
  128. package/dist/commands/ln.js +0 -1
  129. package/dist/commands/ls.d.ts +0 -1
  130. package/dist/commands/ls.js +0 -1
  131. package/dist/commands/lsb-release.d.ts +0 -1
  132. package/dist/commands/lsb-release.js +0 -1
  133. package/dist/commands/man.d.ts +0 -1
  134. package/dist/commands/man.js +0 -1
  135. package/dist/commands/manuals-bundle.d.ts +0 -1
  136. package/dist/commands/manuals-bundle.js +0 -1
  137. package/dist/commands/mkdir.d.ts +0 -1
  138. package/dist/commands/mkdir.js +0 -1
  139. package/dist/commands/mv.d.ts +0 -1
  140. package/dist/commands/mv.js +0 -1
  141. package/dist/commands/nano.d.ts +0 -1
  142. package/dist/commands/nano.js +0 -1
  143. package/dist/commands/neofetch.d.ts +0 -1
  144. package/dist/commands/neofetch.js +0 -1
  145. package/dist/commands/node.d.ts +0 -1
  146. package/dist/commands/node.js +0 -1
  147. package/dist/commands/npm.d.ts +0 -1
  148. package/dist/commands/npm.js +0 -1
  149. package/dist/commands/passwd.d.ts +0 -1
  150. package/dist/commands/passwd.js +0 -1
  151. package/dist/commands/ping.d.ts +0 -1
  152. package/dist/commands/ping.js +0 -1
  153. package/dist/commands/printf.d.ts +0 -1
  154. package/dist/commands/printf.js +0 -1
  155. package/dist/commands/ps.d.ts +0 -1
  156. package/dist/commands/ps.js +0 -1
  157. package/dist/commands/pwd.d.ts +0 -1
  158. package/dist/commands/pwd.js +0 -1
  159. package/dist/commands/python.d.ts +0 -1
  160. package/dist/commands/python.js +0 -1
  161. package/dist/commands/read.d.ts +0 -1
  162. package/dist/commands/read.js +0 -1
  163. package/dist/commands/registry.d.ts +0 -1
  164. package/dist/commands/registry.js +0 -1
  165. package/dist/commands/rm.d.ts +0 -1
  166. package/dist/commands/rm.js +0 -1
  167. package/dist/commands/runtime.d.ts +0 -1
  168. package/dist/commands/runtime.js +139 -107
  169. package/dist/commands/sed.d.ts +0 -1
  170. package/dist/commands/sed.js +0 -1
  171. package/dist/commands/seq.d.ts +0 -1
  172. package/dist/commands/seq.js +0 -1
  173. package/dist/commands/set.d.ts +0 -1
  174. package/dist/commands/set.js +0 -1
  175. package/dist/commands/sh.d.ts +0 -1
  176. package/dist/commands/sh.js +0 -1
  177. package/dist/commands/shift.d.ts +0 -1
  178. package/dist/commands/shift.js +0 -1
  179. package/dist/commands/sleep.d.ts +0 -1
  180. package/dist/commands/sleep.js +0 -1
  181. package/dist/commands/sort.d.ts +0 -1
  182. package/dist/commands/sort.js +0 -1
  183. package/dist/commands/source.d.ts +0 -1
  184. package/dist/commands/source.js +0 -1
  185. package/dist/commands/stat.d.ts +0 -1
  186. package/dist/commands/stat.js +0 -1
  187. package/dist/commands/su.d.ts +0 -1
  188. package/dist/commands/su.js +0 -1
  189. package/dist/commands/sudo.d.ts +0 -1
  190. package/dist/commands/sudo.js +0 -1
  191. package/dist/commands/tail.d.ts +0 -1
  192. package/dist/commands/tail.js +0 -1
  193. package/dist/commands/tar.d.ts +0 -1
  194. package/dist/commands/tar.js +0 -1
  195. package/dist/commands/tee.d.ts +0 -1
  196. package/dist/commands/tee.js +0 -1
  197. package/dist/commands/test.d.ts +0 -1
  198. package/dist/commands/test.js +0 -1
  199. package/dist/commands/touch.d.ts +0 -1
  200. package/dist/commands/touch.js +0 -1
  201. package/dist/commands/tr.d.ts +0 -1
  202. package/dist/commands/tr.js +0 -1
  203. package/dist/commands/tree.d.ts +0 -1
  204. package/dist/commands/tree.js +0 -1
  205. package/dist/commands/true.d.ts +0 -1
  206. package/dist/commands/true.js +0 -1
  207. package/dist/commands/type.d.ts +0 -1
  208. package/dist/commands/type.js +0 -1
  209. package/dist/commands/uname.d.ts +0 -1
  210. package/dist/commands/uname.js +0 -1
  211. package/dist/commands/uniq.d.ts +0 -1
  212. package/dist/commands/uniq.js +0 -1
  213. package/dist/commands/unset.d.ts +0 -1
  214. package/dist/commands/unset.js +0 -1
  215. package/dist/commands/uptime.d.ts +0 -1
  216. package/dist/commands/uptime.js +0 -1
  217. package/dist/commands/wc.d.ts +0 -1
  218. package/dist/commands/wc.js +0 -1
  219. package/dist/commands/wget.d.ts +0 -1
  220. package/dist/commands/wget.js +0 -1
  221. package/dist/commands/which.d.ts +0 -1
  222. package/dist/commands/which.js +0 -1
  223. package/dist/commands/who.d.ts +0 -1
  224. package/dist/commands/who.js +0 -1
  225. package/dist/commands/whoami.d.ts +0 -1
  226. package/dist/commands/whoami.js +0 -1
  227. package/dist/commands/xargs.d.ts +0 -1
  228. package/dist/commands/xargs.js +0 -1
  229. package/dist/index.d.ts +0 -1
  230. package/dist/index.js +0 -1
  231. package/dist/modules/linuxRootfs.d.ts +0 -1
  232. package/dist/modules/linuxRootfs.js +0 -1
  233. package/dist/modules/neofetch.d.ts +0 -1
  234. package/dist/modules/neofetch.js +0 -1
  235. package/dist/modules/shellInteractive.d.ts +0 -1
  236. package/dist/modules/shellInteractive.js +0 -1
  237. package/dist/modules/shellRuntime.d.ts +0 -1
  238. package/dist/modules/shellRuntime.js +0 -1
  239. package/dist/self-standalone.d.ts +0 -1
  240. package/dist/self-standalone.js +0 -1
  241. package/dist/standalone-wo-sftp.d.ts +0 -1
  242. package/dist/standalone-wo-sftp.js +0 -1
  243. package/dist/standalone.d.ts +0 -1
  244. package/dist/standalone.js +0 -1
  245. package/dist/types/commands.d.ts +0 -1
  246. package/dist/types/commands.js +0 -1
  247. package/dist/types/pipeline.d.ts +0 -1
  248. package/dist/types/pipeline.js +0 -1
  249. package/dist/types/streams.d.ts +0 -1
  250. package/dist/types/streams.js +0 -1
  251. package/dist/types/vfs.d.ts +0 -1
  252. package/dist/types/vfs.js +0 -1
  253. package/dist/utils/expand.d.ts +0 -1
  254. package/dist/utils/expand.js +0 -1
  255. package/dist/utils/perfLogger.d.ts +0 -1
  256. package/dist/utils/perfLogger.js +0 -1
  257. package/dist/utils/tokenize.d.ts +0 -1
  258. package/dist/utils/tokenize.js +0 -1
  259. package/dist/utils/vfsDiff.d.ts +0 -1
  260. package/dist/utils/vfsDiff.js +0 -1
  261. package/docs/app.js +1751 -0
  262. package/docs/classes/HoneyPot.html +17 -17
  263. package/docs/classes/IdleManager.html +8 -8
  264. package/docs/classes/SshClient.html +34 -34
  265. package/docs/classes/VirtualFileSystem.html +38 -38
  266. package/docs/classes/VirtualPackageManager.html +19 -19
  267. package/docs/classes/VirtualSftpServer.html +3 -3
  268. package/docs/classes/VirtualShell.html +41 -40
  269. package/docs/classes/VirtualSshServer.html +8 -8
  270. package/docs/classes/VirtualUserManager.html +32 -32
  271. package/docs/demo.html +82 -0
  272. package/docs/functions/assertDiff.html +3 -3
  273. package/docs/functions/diffSnapshots.html +5 -5
  274. package/docs/functions/formatDiff.html +3 -3
  275. package/docs/functions/getArg.html +3 -3
  276. package/docs/functions/getFlag.html +2 -2
  277. package/docs/functions/ifFlag.html +2 -2
  278. package/docs/hierarchy.html +1 -1
  279. package/docs/index.html +41 -19
  280. package/docs/interfaces/AuditLogEntry.html +3 -3
  281. package/docs/interfaces/CommandContext.html +13 -13
  282. package/docs/interfaces/CommandResult.html +13 -13
  283. package/docs/interfaces/ExecStream.html +6 -6
  284. package/docs/interfaces/HoneyPotStats.html +3 -3
  285. package/docs/interfaces/IdleManagerOptions.html +3 -3
  286. package/docs/interfaces/InstalledPackage.html +11 -11
  287. package/docs/interfaces/NanoEditorSession.html +5 -5
  288. package/docs/interfaces/PackageDefinition.html +14 -14
  289. package/docs/interfaces/PackageFile.html +5 -5
  290. package/docs/interfaces/PasswordChallenge.html +9 -9
  291. package/docs/interfaces/RemoveOptions.html +3 -3
  292. package/docs/interfaces/ShellEnv.html +4 -4
  293. package/docs/interfaces/ShellModule.html +8 -8
  294. package/docs/interfaces/ShellProperties.html +5 -5
  295. package/docs/interfaces/ShellStream.html +7 -7
  296. package/docs/interfaces/SudoChallenge.html +9 -9
  297. package/docs/interfaces/VfsBaseNode.html +7 -7
  298. package/docs/interfaces/VfsDiff.html +7 -7
  299. package/docs/interfaces/VfsDiffEntry.html +4 -4
  300. package/docs/interfaces/VfsDiffModified.html +6 -6
  301. package/docs/interfaces/VfsDirectoryNode.html +8 -8
  302. package/docs/interfaces/VfsFileNode.html +9 -9
  303. package/docs/interfaces/VfsOptions.html +6 -6
  304. package/docs/interfaces/VfsSnapshot.html +3 -3
  305. package/docs/interfaces/VfsSnapshotBaseNode.html +4 -4
  306. package/docs/interfaces/VfsSnapshotDirectoryNode.html +5 -5
  307. package/docs/interfaces/VfsSnapshotFileNode.html +6 -6
  308. package/docs/interfaces/VirtualActiveSession.html +7 -7
  309. package/docs/interfaces/VirtualSftpServerOptions.html +3 -3
  310. package/docs/interfaces/VirtualShellVfsLike.html +4 -4
  311. package/docs/interfaces/VirtualShellVfsOptions.html +3 -3
  312. package/docs/interfaces/WriteFileOptions.html +4 -4
  313. package/docs/modules.html +1 -1
  314. package/docs/types/ArgParseOptions.html +3 -3
  315. package/docs/types/CommandMode.html +2 -2
  316. package/docs/types/CommandOutcome.html +2 -2
  317. package/docs/types/IdleState.html +1 -1
  318. package/docs/types/VfsNodeStats.html +2 -2
  319. package/docs/types/VfsNodeType.html +2 -2
  320. package/docs/types/VfsPersistenceMode.html +2 -2
  321. package/docs/types/VfsSnapshotNode.html +2 -2
  322. package/examples/app.js +1751 -28
  323. package/examples/app.ts +299 -0
  324. package/examples/build.js +27 -0
  325. package/examples/demo.html +33 -0
  326. package/examples/index.html +68 -13
  327. package/package.json +3 -2
  328. package/polyfills/buffer.js +117 -0
  329. package/polyfills/node_crypto/index.js +167 -7
  330. package/polyfills/node_fs/index.js +202 -8
  331. package/polyfills/node_path/index.js +23 -9
  332. package/polyfills/process.js +14 -0
  333. package/polyfills/ssh2/index.js +75 -0
  334. package/scripts/build-all.mjs +77 -49
  335. package/scripts/build-names.mjs +2 -3
  336. package/src/VirtualPackageManager/index.ts +4 -15
  337. package/src/VirtualShell/index.ts +5 -2
  338. package/src/commands/runtime.ts +44 -1
  339. package/tsconfig.json +6 -3
  340. package/typedoc.json +4 -2
  341. package/builds/fortune-nyx-v1.5.1-web-full.min.js +0 -12
  342. package/builds/fortune-nyx-v1.5.1-web.min.js +0 -12
  343. package/dist/Honeypot/index.d.ts.map +0 -1
  344. package/dist/Honeypot/index.js.map +0 -1
  345. package/dist/SSHClient/index.d.ts.map +0 -1
  346. package/dist/SSHClient/index.js.map +0 -1
  347. package/dist/SSHMimic/exec.d.ts.map +0 -1
  348. package/dist/SSHMimic/exec.js.map +0 -1
  349. package/dist/SSHMimic/executor.d.ts.map +0 -1
  350. package/dist/SSHMimic/executor.js.map +0 -1
  351. package/dist/SSHMimic/hostKey.d.ts.map +0 -1
  352. package/dist/SSHMimic/hostKey.js.map +0 -1
  353. package/dist/SSHMimic/index.d.ts.map +0 -1
  354. package/dist/SSHMimic/index.js.map +0 -1
  355. package/dist/SSHMimic/loginBanner.d.ts.map +0 -1
  356. package/dist/SSHMimic/loginBanner.js.map +0 -1
  357. package/dist/SSHMimic/loginFormat.d.ts.map +0 -1
  358. package/dist/SSHMimic/loginFormat.js.map +0 -1
  359. package/dist/SSHMimic/prompt.d.ts.map +0 -1
  360. package/dist/SSHMimic/prompt.js.map +0 -1
  361. package/dist/SSHMimic/sftp.d.ts.map +0 -1
  362. package/dist/SSHMimic/sftp.js.map +0 -1
  363. package/dist/VirtualFileSystem/binaryPack.d.ts.map +0 -1
  364. package/dist/VirtualFileSystem/binaryPack.js.map +0 -1
  365. package/dist/VirtualFileSystem/index.d.ts.map +0 -1
  366. package/dist/VirtualFileSystem/index.js.map +0 -1
  367. package/dist/VirtualFileSystem/internalTypes.d.ts.map +0 -1
  368. package/dist/VirtualFileSystem/internalTypes.js.map +0 -1
  369. package/dist/VirtualFileSystem/journal.d.ts.map +0 -1
  370. package/dist/VirtualFileSystem/journal.js.map +0 -1
  371. package/dist/VirtualFileSystem/path.d.ts.map +0 -1
  372. package/dist/VirtualFileSystem/path.js.map +0 -1
  373. package/dist/VirtualPackageManager/index.d.ts.map +0 -1
  374. package/dist/VirtualPackageManager/index.js.map +0 -1
  375. package/dist/VirtualShell/idleManager.d.ts.map +0 -1
  376. package/dist/VirtualShell/idleManager.js.map +0 -1
  377. package/dist/VirtualShell/index.d.ts.map +0 -1
  378. package/dist/VirtualShell/index.js.map +0 -1
  379. package/dist/VirtualShell/shell.d.ts.map +0 -1
  380. package/dist/VirtualShell/shell.js.map +0 -1
  381. package/dist/VirtualShell/shellParser.d.ts.map +0 -1
  382. package/dist/VirtualShell/shellParser.js.map +0 -1
  383. package/dist/VirtualUserManager/index.d.ts.map +0 -1
  384. package/dist/VirtualUserManager/index.js.map +0 -1
  385. package/dist/commands/adduser.d.ts.map +0 -1
  386. package/dist/commands/adduser.js.map +0 -1
  387. package/dist/commands/alias.d.ts.map +0 -1
  388. package/dist/commands/alias.js.map +0 -1
  389. package/dist/commands/apt.d.ts.map +0 -1
  390. package/dist/commands/apt.js.map +0 -1
  391. package/dist/commands/awk.d.ts.map +0 -1
  392. package/dist/commands/awk.js.map +0 -1
  393. package/dist/commands/base64.d.ts.map +0 -1
  394. package/dist/commands/base64.js.map +0 -1
  395. package/dist/commands/cat.d.ts.map +0 -1
  396. package/dist/commands/cat.js.map +0 -1
  397. package/dist/commands/cd.d.ts.map +0 -1
  398. package/dist/commands/cd.js.map +0 -1
  399. package/dist/commands/chmod.d.ts.map +0 -1
  400. package/dist/commands/chmod.js.map +0 -1
  401. package/dist/commands/clear.d.ts.map +0 -1
  402. package/dist/commands/clear.js.map +0 -1
  403. package/dist/commands/command-helpers.d.ts.map +0 -1
  404. package/dist/commands/command-helpers.js.map +0 -1
  405. package/dist/commands/cp.d.ts.map +0 -1
  406. package/dist/commands/cp.js.map +0 -1
  407. package/dist/commands/curl.d.ts.map +0 -1
  408. package/dist/commands/curl.js.map +0 -1
  409. package/dist/commands/cut.d.ts.map +0 -1
  410. package/dist/commands/cut.js.map +0 -1
  411. package/dist/commands/date.d.ts.map +0 -1
  412. package/dist/commands/date.js.map +0 -1
  413. package/dist/commands/declare.d.ts.map +0 -1
  414. package/dist/commands/declare.js.map +0 -1
  415. package/dist/commands/deluser.d.ts.map +0 -1
  416. package/dist/commands/deluser.js.map +0 -1
  417. package/dist/commands/df.d.ts.map +0 -1
  418. package/dist/commands/df.js.map +0 -1
  419. package/dist/commands/diff.d.ts.map +0 -1
  420. package/dist/commands/diff.js.map +0 -1
  421. package/dist/commands/dpkg.d.ts.map +0 -1
  422. package/dist/commands/dpkg.js.map +0 -1
  423. package/dist/commands/du.d.ts.map +0 -1
  424. package/dist/commands/du.js.map +0 -1
  425. package/dist/commands/echo.d.ts.map +0 -1
  426. package/dist/commands/echo.js.map +0 -1
  427. package/dist/commands/env.d.ts.map +0 -1
  428. package/dist/commands/env.js.map +0 -1
  429. package/dist/commands/exit.d.ts.map +0 -1
  430. package/dist/commands/exit.js.map +0 -1
  431. package/dist/commands/export.d.ts.map +0 -1
  432. package/dist/commands/export.js.map +0 -1
  433. package/dist/commands/find.d.ts.map +0 -1
  434. package/dist/commands/find.js.map +0 -1
  435. package/dist/commands/free.d.ts.map +0 -1
  436. package/dist/commands/free.js.map +0 -1
  437. package/dist/commands/grep.d.ts.map +0 -1
  438. package/dist/commands/grep.js.map +0 -1
  439. package/dist/commands/groups.d.ts.map +0 -1
  440. package/dist/commands/groups.js.map +0 -1
  441. package/dist/commands/gzip.d.ts.map +0 -1
  442. package/dist/commands/gzip.js.map +0 -1
  443. package/dist/commands/head.d.ts.map +0 -1
  444. package/dist/commands/head.js.map +0 -1
  445. package/dist/commands/help.d.ts.map +0 -1
  446. package/dist/commands/help.js.map +0 -1
  447. package/dist/commands/helpers.d.ts.map +0 -1
  448. package/dist/commands/helpers.js.map +0 -1
  449. package/dist/commands/history.d.ts.map +0 -1
  450. package/dist/commands/history.js.map +0 -1
  451. package/dist/commands/hostname.d.ts.map +0 -1
  452. package/dist/commands/hostname.js.map +0 -1
  453. package/dist/commands/htop.d.ts.map +0 -1
  454. package/dist/commands/htop.js.map +0 -1
  455. package/dist/commands/id.d.ts.map +0 -1
  456. package/dist/commands/id.js.map +0 -1
  457. package/dist/commands/index.d.ts.map +0 -1
  458. package/dist/commands/index.js.map +0 -1
  459. package/dist/commands/kill.d.ts.map +0 -1
  460. package/dist/commands/kill.js.map +0 -1
  461. package/dist/commands/ln.d.ts.map +0 -1
  462. package/dist/commands/ln.js.map +0 -1
  463. package/dist/commands/ls.d.ts.map +0 -1
  464. package/dist/commands/ls.js.map +0 -1
  465. package/dist/commands/lsb-release.d.ts.map +0 -1
  466. package/dist/commands/lsb-release.js.map +0 -1
  467. package/dist/commands/man.d.ts.map +0 -1
  468. package/dist/commands/man.js.map +0 -1
  469. package/dist/commands/manuals-bundle.d.ts.map +0 -1
  470. package/dist/commands/manuals-bundle.js.map +0 -1
  471. package/dist/commands/mkdir.d.ts.map +0 -1
  472. package/dist/commands/mkdir.js.map +0 -1
  473. package/dist/commands/mv.d.ts.map +0 -1
  474. package/dist/commands/mv.js.map +0 -1
  475. package/dist/commands/nano.d.ts.map +0 -1
  476. package/dist/commands/nano.js.map +0 -1
  477. package/dist/commands/neofetch.d.ts.map +0 -1
  478. package/dist/commands/neofetch.js.map +0 -1
  479. package/dist/commands/node.d.ts.map +0 -1
  480. package/dist/commands/node.js.map +0 -1
  481. package/dist/commands/npm.d.ts.map +0 -1
  482. package/dist/commands/npm.js.map +0 -1
  483. package/dist/commands/passwd.d.ts.map +0 -1
  484. package/dist/commands/passwd.js.map +0 -1
  485. package/dist/commands/ping.d.ts.map +0 -1
  486. package/dist/commands/ping.js.map +0 -1
  487. package/dist/commands/printf.d.ts.map +0 -1
  488. package/dist/commands/printf.js.map +0 -1
  489. package/dist/commands/ps.d.ts.map +0 -1
  490. package/dist/commands/ps.js.map +0 -1
  491. package/dist/commands/pwd.d.ts.map +0 -1
  492. package/dist/commands/pwd.js.map +0 -1
  493. package/dist/commands/python.d.ts.map +0 -1
  494. package/dist/commands/python.js.map +0 -1
  495. package/dist/commands/read.d.ts.map +0 -1
  496. package/dist/commands/read.js.map +0 -1
  497. package/dist/commands/registry.d.ts.map +0 -1
  498. package/dist/commands/registry.js.map +0 -1
  499. package/dist/commands/rm.d.ts.map +0 -1
  500. package/dist/commands/rm.js.map +0 -1
  501. package/dist/commands/runtime.d.ts.map +0 -1
  502. package/dist/commands/runtime.js.map +0 -1
  503. package/dist/commands/sed.d.ts.map +0 -1
  504. package/dist/commands/sed.js.map +0 -1
  505. package/dist/commands/seq.d.ts.map +0 -1
  506. package/dist/commands/seq.js.map +0 -1
  507. package/dist/commands/set.d.ts.map +0 -1
  508. package/dist/commands/set.js.map +0 -1
  509. package/dist/commands/sh.d.ts.map +0 -1
  510. package/dist/commands/sh.js.map +0 -1
  511. package/dist/commands/shift.d.ts.map +0 -1
  512. package/dist/commands/shift.js.map +0 -1
  513. package/dist/commands/sleep.d.ts.map +0 -1
  514. package/dist/commands/sleep.js.map +0 -1
  515. package/dist/commands/sort.d.ts.map +0 -1
  516. package/dist/commands/sort.js.map +0 -1
  517. package/dist/commands/source.d.ts.map +0 -1
  518. package/dist/commands/source.js.map +0 -1
  519. package/dist/commands/stat.d.ts.map +0 -1
  520. package/dist/commands/stat.js.map +0 -1
  521. package/dist/commands/su.d.ts.map +0 -1
  522. package/dist/commands/su.js.map +0 -1
  523. package/dist/commands/sudo.d.ts.map +0 -1
  524. package/dist/commands/sudo.js.map +0 -1
  525. package/dist/commands/tail.d.ts.map +0 -1
  526. package/dist/commands/tail.js.map +0 -1
  527. package/dist/commands/tar.d.ts.map +0 -1
  528. package/dist/commands/tar.js.map +0 -1
  529. package/dist/commands/tee.d.ts.map +0 -1
  530. package/dist/commands/tee.js.map +0 -1
  531. package/dist/commands/test.d.ts.map +0 -1
  532. package/dist/commands/test.js.map +0 -1
  533. package/dist/commands/touch.d.ts.map +0 -1
  534. package/dist/commands/touch.js.map +0 -1
  535. package/dist/commands/tr.d.ts.map +0 -1
  536. package/dist/commands/tr.js.map +0 -1
  537. package/dist/commands/tree.d.ts.map +0 -1
  538. package/dist/commands/tree.js.map +0 -1
  539. package/dist/commands/true.d.ts.map +0 -1
  540. package/dist/commands/true.js.map +0 -1
  541. package/dist/commands/type.d.ts.map +0 -1
  542. package/dist/commands/type.js.map +0 -1
  543. package/dist/commands/uname.d.ts.map +0 -1
  544. package/dist/commands/uname.js.map +0 -1
  545. package/dist/commands/uniq.d.ts.map +0 -1
  546. package/dist/commands/uniq.js.map +0 -1
  547. package/dist/commands/unset.d.ts.map +0 -1
  548. package/dist/commands/unset.js.map +0 -1
  549. package/dist/commands/uptime.d.ts.map +0 -1
  550. package/dist/commands/uptime.js.map +0 -1
  551. package/dist/commands/wc.d.ts.map +0 -1
  552. package/dist/commands/wc.js.map +0 -1
  553. package/dist/commands/wget.d.ts.map +0 -1
  554. package/dist/commands/wget.js.map +0 -1
  555. package/dist/commands/which.d.ts.map +0 -1
  556. package/dist/commands/which.js.map +0 -1
  557. package/dist/commands/who.d.ts.map +0 -1
  558. package/dist/commands/who.js.map +0 -1
  559. package/dist/commands/whoami.d.ts.map +0 -1
  560. package/dist/commands/whoami.js.map +0 -1
  561. package/dist/commands/xargs.d.ts.map +0 -1
  562. package/dist/commands/xargs.js.map +0 -1
  563. package/dist/index.d.ts.map +0 -1
  564. package/dist/index.js.map +0 -1
  565. package/dist/modules/linuxRootfs.d.ts.map +0 -1
  566. package/dist/modules/linuxRootfs.js.map +0 -1
  567. package/dist/modules/neofetch.d.ts.map +0 -1
  568. package/dist/modules/neofetch.js.map +0 -1
  569. package/dist/modules/shellInteractive.d.ts.map +0 -1
  570. package/dist/modules/shellInteractive.js.map +0 -1
  571. package/dist/modules/shellRuntime.d.ts.map +0 -1
  572. package/dist/modules/shellRuntime.js.map +0 -1
  573. package/dist/self-standalone.d.ts.map +0 -1
  574. package/dist/self-standalone.js.map +0 -1
  575. package/dist/standalone-wo-sftp.d.ts.map +0 -1
  576. package/dist/standalone-wo-sftp.js.map +0 -1
  577. package/dist/standalone.d.ts.map +0 -1
  578. package/dist/standalone.js.map +0 -1
  579. package/dist/types/commands.d.ts.map +0 -1
  580. package/dist/types/commands.js.map +0 -1
  581. package/dist/types/pipeline.d.ts.map +0 -1
  582. package/dist/types/pipeline.js.map +0 -1
  583. package/dist/types/streams.d.ts.map +0 -1
  584. package/dist/types/streams.js.map +0 -1
  585. package/dist/types/vfs.d.ts.map +0 -1
  586. package/dist/types/vfs.js.map +0 -1
  587. package/dist/utils/expand.d.ts.map +0 -1
  588. package/dist/utils/expand.js.map +0 -1
  589. package/dist/utils/perfLogger.d.ts.map +0 -1
  590. package/dist/utils/perfLogger.js.map +0 -1
  591. package/dist/utils/tokenize.d.ts.map +0 -1
  592. package/dist/utils/tokenize.js.map +0 -1
  593. package/dist/utils/vfsDiff.d.ts.map +0 -1
  594. package/dist/utils/vfsDiff.js.map +0 -1
  595. package/dist/web-api.d.ts +0 -26
  596. package/dist/web-api.d.ts.map +0 -1
  597. package/dist/web-api.js +0 -47
  598. package/dist/web-api.js.map +0 -1
  599. package/dist/web-full.d.ts +0 -4
  600. package/dist/web-full.d.ts.map +0 -1
  601. package/dist/web-full.js +0 -9
  602. package/dist/web-full.js.map +0 -1
  603. package/dist/web.d.ts +0 -108
  604. package/dist/web.d.ts.map +0 -1
  605. package/dist/web.js +0 -774
  606. package/dist/web.js.map +0 -1
  607. package/examples/app-iife.js +0 -58
  608. package/examples/index-cf.html +0 -27
  609. package/examples/web-iife.min.js +0 -13
  610. package/examples/web.min.js +0 -12
  611. package/src/web-api.ts +0 -62
  612. package/src/web-full.ts +0 -11
  613. package/src/web.ts +0 -930
  614. package/tests/web.test.ts +0 -182
@@ -1,32 +1,32 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var dp=Object.create;var Dc=Object.defineProperty;var hp=Object.getOwnPropertyDescriptor;var pp=Object.getOwnPropertyNames;var mp=Object.getPrototypeOf,gp=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))!gp.call(n,s)&&s!==e&&Dc(n,s,{get:()=>t[s],enumerable:!(r=hp(t,s))||r.enumerable});return n};var Yt=(n,t,e)=>(e=n!=null?dp(mp(n)):{},Ap(t||!n||!n.__esModule?Dc(e,"default",{value:n,enumerable:!0}):e,n));var Yi=lt((Vy,Uc)=>{Uc.exports={newInvalidAsn1Error:function(n){var t=new Error;return t.name="InvalidAsn1Error",t.message=n||"",t}}});var ji=lt((zy,$c)=>{$c.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 go=lt((Gy,Fc)=>{"use strict";var Xi=require("buffer"),Nr=Xi.Buffer,mn={},gn;for(gn in Xi)Xi.hasOwnProperty(gn)&&(gn==="SlowBuffer"||gn==="Buffer"||(mn[gn]=Xi[gn]));var Br=mn.Buffer={};for(gn in Nr)Nr.hasOwnProperty(gn)&&(gn==="allocUnsafe"||gn==="allocUnsafeSlow"||(Br[gn]=Nr[gn]));mn.Buffer.prototype=Nr.prototype;(!Br.from||Br.from===Uint8Array.from)&&(Br.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 Nr(n,t,e)});Br.alloc||(Br.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=Nr(n);return!t||t.length===0?r.fill(0):typeof e=="string"?r.fill(t,e):r.fill(t),r});if(!mn.kStringMaxLength)try{mn.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch{}mn.constants||(mn.constants={MAX_LENGTH:mn.kMaxLength},mn.kStringMaxLength&&(mn.constants.MAX_STRING_LENGTH=mn.kStringMaxLength));Fc.exports=mn});var Wc=lt((Yy,Qc)=>{var yp=require("assert"),Hc=go().Buffer,ci=ji(),Ep=Yi(),Rr=Ep.newInvalidAsn1Error;function Jt(n){if(!n||!Hc.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 Rr("Indefinite length not supported");if(t>4)throw Rr("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 Rr("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(ci.Integer)};Jt.prototype.readBoolean=function(){return this._readTag(ci.Boolean)!==0};Jt.prototype.readEnumeration=function(){return this._readTag(ci.Enumeration)};Jt.prototype.readString=function(n,t){n||(n=ci.OctetString);var e=this.peek();if(e===null)return null;if(e!==n)throw Rr("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?Hc.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=ci.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){yp.ok(n!==void 0);var t=this.peek();if(t===null)return null;if(t!==n)throw Rr("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 Rr("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};Qc.exports=Jt});var Kc=lt((jy,qc)=>{var Kn=require("assert"),Ji=go().Buffer,Vn=ji(),_p=Yi(),Zi=_p.newInvalidAsn1Error,bp={size:1024,growthFactor:8};function Sp(n,t){Kn.ok(n),Kn.equal(typeof n,"object"),Kn.ok(t),Kn.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 jt(n){n=Sp(bp,n||{}),this._buf=Ji.alloc(n.size||1024),this._size=this._buf.length,this._offset=0,this._options=n,this._seq=[]}Object.defineProperty(jt.prototype,"buffer",{get:function(){if(this._seq.length)throw Zi(this._seq.length+" unended sequence(s)");return this._buf.slice(0,this._offset)}});jt.prototype.writeByte=function(n){if(typeof n!="number")throw new TypeError("argument must be a Number");this._ensure(1),this._buf[this._offset++]=n};jt.prototype.writeInt=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");typeof t!="number"&&(t=Vn.Integer);for(var e=4;((n&4286578688)===0||(n&4286578688)===-8388608)&&e>1;)e--,n<<=8;if(e>4)throw Zi("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};jt.prototype.writeNull=function(){this.writeByte(Vn.Null),this.writeByte(0)};jt.prototype.writeEnumeration=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");return typeof t!="number"&&(t=Vn.Enumeration),this.writeInt(n,t)};jt.prototype.writeBoolean=function(n,t){if(typeof n!="boolean")throw new TypeError("argument must be a Boolean");typeof t!="number"&&(t=Vn.Boolean),this._ensure(3),this._buf[this._offset++]=t,this._buf[this._offset++]=1,this._buf[this._offset++]=n?255:0};jt.prototype.writeString=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string (was: "+typeof n+")");typeof t!="number"&&(t=Vn.OctetString);var e=Ji.byteLength(n);this.writeByte(t),this.writeLength(e),e&&(this._ensure(e),this._buf.write(n,this._offset),this._offset+=e)};jt.prototype.writeBuffer=function(n,t){if(typeof t!="number")throw new TypeError("tag must be a number");if(!Ji.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};jt.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)})};jt.prototype.writeOID=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string");if(typeof t!="number"&&(t=Vn.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)})};jt.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 Zi("Length too long (> 4 bytes)")};jt.prototype.startSequence=function(n){typeof n!="number"&&(n=Vn.Sequence|Vn.Constructor),this.writeByte(n),this._seq.push(this._offset),this._ensure(3),this._offset+=3};jt.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 Zi("Sequence too long")};jt.prototype._shift=function(n,t,e){Kn.ok(n!==void 0),Kn.ok(t!==void 0),Kn.ok(e),this._buf.copy(this._buf,n+e,n,n+t),this._offset+=e};jt.prototype._ensure=function(n){if(Kn.ok(n),this._size-this._offset<n){var t=this._size*this._options.growthFactor;t-this._offset<n&&(t+=n);var e=Ji.alloc(t);this._buf.copy(e,0,0,this._offset),this._buf=e,this._size=t}};qc.exports=jt});var Vc=lt((Xy,ns)=>{var Ao=Yi(),yo=ji(),xp=Wc(),wp=Kc();ns.exports={Reader:xp,Writer:wp};for(es in yo)yo.hasOwnProperty(es)&&(ns.exports[es]=yo[es]);var es;for(ts in Ao)Ao.hasOwnProperty(ts)&&(ns.exports[ts]=Ao[ts]);var ts});var li=lt((Jy,zc)=>{var Eo=Vc();zc.exports={Ber:Eo,BerReader:Eo.Reader,BerWriter:Eo.Writer}});var Gc=lt((Zy,rs)=>{(function(n){"use strict";var t=function(m){var A,g=new Float64Array(16);if(m)for(A=0;A<m.length;A++)g[A]=m[A];return g},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]),u=t([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),f=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(m,A,g,d){m[A]=g>>24&255,m[A+1]=g>>16&255,m[A+2]=g>>8&255,m[A+3]=g&255,m[A+4]=d>>24&255,m[A+5]=d>>16&255,m[A+6]=d>>8&255,m[A+7]=d&255}function y(m,A,g,d,_){var D,W=0;for(D=0;D<_;D++)W|=m[A+D]^g[d+D];return(1&W-1>>>8)-1}function E(m,A,g,d){return y(m,A,g,d,16)}function S(m,A,g,d){return y(m,A,g,d,32)}function x(m,A,g,d){for(var _=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,D=g[0]&255|(g[1]&255)<<8|(g[2]&255)<<16|(g[3]&255)<<24,W=g[4]&255|(g[5]&255)<<8|(g[6]&255)<<16|(g[7]&255)<<24,ee=g[8]&255|(g[9]&255)<<8|(g[10]&255)<<16|(g[11]&255)<<24,le=g[12]&255|(g[13]&255)<<8|(g[14]&255)<<16|(g[15]&255)<<24,Ee=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,ge=A[0]&255|(A[1]&255)<<8|(A[2]&255)<<16|(A[3]&255)<<24,it=A[4]&255|(A[5]&255)<<8|(A[6]&255)<<16|(A[7]&255)<<24,ye=A[8]&255|(A[9]&255)<<8|(A[10]&255)<<16|(A[11]&255)<<24,Me=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,Qe=g[16]&255|(g[17]&255)<<8|(g[18]&255)<<16|(g[19]&255)<<24,He=g[20]&255|(g[21]&255)<<8|(g[22]&255)<<16|(g[23]&255)<<24,De=g[24]&255|(g[25]&255)<<8|(g[26]&255)<<16|(g[27]&255)<<24,$e=g[28]&255|(g[29]&255)<<8|(g[30]&255)<<16|(g[31]&255)<<24,Ue=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,_e=_,xe=D,Ae=W,be=ee,Se=le,me=Ee,K=ge,V=it,se=ye,Z=Me,te=Le,ce=Qe,ve=He,We=De,Ke=$e,qe=Ue,I,ze=0;ze<20;ze+=2)I=_e+ve|0,Se^=I<<7|I>>>25,I=Se+_e|0,se^=I<<9|I>>>23,I=se+Se|0,ve^=I<<13|I>>>19,I=ve+se|0,_e^=I<<18|I>>>14,I=me+xe|0,Z^=I<<7|I>>>25,I=Z+me|0,We^=I<<9|I>>>23,I=We+Z|0,xe^=I<<13|I>>>19,I=xe+We|0,me^=I<<18|I>>>14,I=te+K|0,Ke^=I<<7|I>>>25,I=Ke+te|0,Ae^=I<<9|I>>>23,I=Ae+Ke|0,K^=I<<13|I>>>19,I=K+Ae|0,te^=I<<18|I>>>14,I=qe+ce|0,be^=I<<7|I>>>25,I=be+qe|0,V^=I<<9|I>>>23,I=V+be|0,ce^=I<<13|I>>>19,I=ce+V|0,qe^=I<<18|I>>>14,I=_e+be|0,xe^=I<<7|I>>>25,I=xe+_e|0,Ae^=I<<9|I>>>23,I=Ae+xe|0,be^=I<<13|I>>>19,I=be+Ae|0,_e^=I<<18|I>>>14,I=me+Se|0,K^=I<<7|I>>>25,I=K+me|0,V^=I<<9|I>>>23,I=V+K|0,Se^=I<<13|I>>>19,I=Se+V|0,me^=I<<18|I>>>14,I=te+Z|0,ce^=I<<7|I>>>25,I=ce+te|0,se^=I<<9|I>>>23,I=se+ce|0,Z^=I<<13|I>>>19,I=Z+se|0,te^=I<<18|I>>>14,I=qe+Ke|0,ve^=I<<7|I>>>25,I=ve+qe|0,We^=I<<9|I>>>23,I=We+ve|0,Ke^=I<<13|I>>>19,I=Ke+We|0,qe^=I<<18|I>>>14;_e=_e+_|0,xe=xe+D|0,Ae=Ae+W|0,be=be+ee|0,Se=Se+le|0,me=me+Ee|0,K=K+ge|0,V=V+it|0,se=se+ye|0,Z=Z+Me|0,te=te+Le|0,ce=ce+Qe|0,ve=ve+He|0,We=We+De|0,Ke=Ke+$e|0,qe=qe+Ue|0,m[0]=_e>>>0&255,m[1]=_e>>>8&255,m[2]=_e>>>16&255,m[3]=_e>>>24&255,m[4]=xe>>>0&255,m[5]=xe>>>8&255,m[6]=xe>>>16&255,m[7]=xe>>>24&255,m[8]=Ae>>>0&255,m[9]=Ae>>>8&255,m[10]=Ae>>>16&255,m[11]=Ae>>>24&255,m[12]=be>>>0&255,m[13]=be>>>8&255,m[14]=be>>>16&255,m[15]=be>>>24&255,m[16]=Se>>>0&255,m[17]=Se>>>8&255,m[18]=Se>>>16&255,m[19]=Se>>>24&255,m[20]=me>>>0&255,m[21]=me>>>8&255,m[22]=me>>>16&255,m[23]=me>>>24&255,m[24]=K>>>0&255,m[25]=K>>>8&255,m[26]=K>>>16&255,m[27]=K>>>24&255,m[28]=V>>>0&255,m[29]=V>>>8&255,m[30]=V>>>16&255,m[31]=V>>>24&255,m[32]=se>>>0&255,m[33]=se>>>8&255,m[34]=se>>>16&255,m[35]=se>>>24&255,m[36]=Z>>>0&255,m[37]=Z>>>8&255,m[38]=Z>>>16&255,m[39]=Z>>>24&255,m[40]=te>>>0&255,m[41]=te>>>8&255,m[42]=te>>>16&255,m[43]=te>>>24&255,m[44]=ce>>>0&255,m[45]=ce>>>8&255,m[46]=ce>>>16&255,m[47]=ce>>>24&255,m[48]=ve>>>0&255,m[49]=ve>>>8&255,m[50]=ve>>>16&255,m[51]=ve>>>24&255,m[52]=We>>>0&255,m[53]=We>>>8&255,m[54]=We>>>16&255,m[55]=We>>>24&255,m[56]=Ke>>>0&255,m[57]=Ke>>>8&255,m[58]=Ke>>>16&255,m[59]=Ke>>>24&255,m[60]=qe>>>0&255,m[61]=qe>>>8&255,m[62]=qe>>>16&255,m[63]=qe>>>24&255}function P(m,A,g,d){for(var _=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,D=g[0]&255|(g[1]&255)<<8|(g[2]&255)<<16|(g[3]&255)<<24,W=g[4]&255|(g[5]&255)<<8|(g[6]&255)<<16|(g[7]&255)<<24,ee=g[8]&255|(g[9]&255)<<8|(g[10]&255)<<16|(g[11]&255)<<24,le=g[12]&255|(g[13]&255)<<8|(g[14]&255)<<16|(g[15]&255)<<24,Ee=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,ge=A[0]&255|(A[1]&255)<<8|(A[2]&255)<<16|(A[3]&255)<<24,it=A[4]&255|(A[5]&255)<<8|(A[6]&255)<<16|(A[7]&255)<<24,ye=A[8]&255|(A[9]&255)<<8|(A[10]&255)<<16|(A[11]&255)<<24,Me=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,Qe=g[16]&255|(g[17]&255)<<8|(g[18]&255)<<16|(g[19]&255)<<24,He=g[20]&255|(g[21]&255)<<8|(g[22]&255)<<16|(g[23]&255)<<24,De=g[24]&255|(g[25]&255)<<8|(g[26]&255)<<16|(g[27]&255)<<24,$e=g[28]&255|(g[29]&255)<<8|(g[30]&255)<<16|(g[31]&255)<<24,Ue=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,_e=_,xe=D,Ae=W,be=ee,Se=le,me=Ee,K=ge,V=it,se=ye,Z=Me,te=Le,ce=Qe,ve=He,We=De,Ke=$e,qe=Ue,I,ze=0;ze<20;ze+=2)I=_e+ve|0,Se^=I<<7|I>>>25,I=Se+_e|0,se^=I<<9|I>>>23,I=se+Se|0,ve^=I<<13|I>>>19,I=ve+se|0,_e^=I<<18|I>>>14,I=me+xe|0,Z^=I<<7|I>>>25,I=Z+me|0,We^=I<<9|I>>>23,I=We+Z|0,xe^=I<<13|I>>>19,I=xe+We|0,me^=I<<18|I>>>14,I=te+K|0,Ke^=I<<7|I>>>25,I=Ke+te|0,Ae^=I<<9|I>>>23,I=Ae+Ke|0,K^=I<<13|I>>>19,I=K+Ae|0,te^=I<<18|I>>>14,I=qe+ce|0,be^=I<<7|I>>>25,I=be+qe|0,V^=I<<9|I>>>23,I=V+be|0,ce^=I<<13|I>>>19,I=ce+V|0,qe^=I<<18|I>>>14,I=_e+be|0,xe^=I<<7|I>>>25,I=xe+_e|0,Ae^=I<<9|I>>>23,I=Ae+xe|0,be^=I<<13|I>>>19,I=be+Ae|0,_e^=I<<18|I>>>14,I=me+Se|0,K^=I<<7|I>>>25,I=K+me|0,V^=I<<9|I>>>23,I=V+K|0,Se^=I<<13|I>>>19,I=Se+V|0,me^=I<<18|I>>>14,I=te+Z|0,ce^=I<<7|I>>>25,I=ce+te|0,se^=I<<9|I>>>23,I=se+ce|0,Z^=I<<13|I>>>19,I=Z+se|0,te^=I<<18|I>>>14,I=qe+Ke|0,ve^=I<<7|I>>>25,I=ve+qe|0,We^=I<<9|I>>>23,I=We+ve|0,Ke^=I<<13|I>>>19,I=Ke+We|0,qe^=I<<18|I>>>14;m[0]=_e>>>0&255,m[1]=_e>>>8&255,m[2]=_e>>>16&255,m[3]=_e>>>24&255,m[4]=me>>>0&255,m[5]=me>>>8&255,m[6]=me>>>16&255,m[7]=me>>>24&255,m[8]=te>>>0&255,m[9]=te>>>8&255,m[10]=te>>>16&255,m[11]=te>>>24&255,m[12]=qe>>>0&255,m[13]=qe>>>8&255,m[14]=qe>>>16&255,m[15]=qe>>>24&255,m[16]=K>>>0&255,m[17]=K>>>8&255,m[18]=K>>>16&255,m[19]=K>>>24&255,m[20]=V>>>0&255,m[21]=V>>>8&255,m[22]=V>>>16&255,m[23]=V>>>24&255,m[24]=se>>>0&255,m[25]=se>>>8&255,m[26]=se>>>16&255,m[27]=se>>>24&255,m[28]=Z>>>0&255,m[29]=Z>>>8&255,m[30]=Z>>>16&255,m[31]=Z>>>24&255}function q(m,A,g,d){x(m,A,g,d)}function C(m,A,g,d){P(m,A,g,d)}var $=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function F(m,A,g,d,_,D,W){var ee=new Uint8Array(16),le=new Uint8Array(64),Ee,ge;for(ge=0;ge<16;ge++)ee[ge]=0;for(ge=0;ge<8;ge++)ee[ge]=D[ge];for(;_>=64;){for(q(le,ee,W,$),ge=0;ge<64;ge++)m[A+ge]=g[d+ge]^le[ge];for(Ee=1,ge=8;ge<16;ge++)Ee=Ee+(ee[ge]&255)|0,ee[ge]=Ee&255,Ee>>>=8;_-=64,A+=64,d+=64}if(_>0)for(q(le,ee,W,$),ge=0;ge<_;ge++)m[A+ge]=g[d+ge]^le[ge];return 0}function v(m,A,g,d,_){var D=new Uint8Array(16),W=new Uint8Array(64),ee,le;for(le=0;le<16;le++)D[le]=0;for(le=0;le<8;le++)D[le]=d[le];for(;g>=64;){for(q(W,D,_,$),le=0;le<64;le++)m[A+le]=W[le];for(ee=1,le=8;le<16;le++)ee=ee+(D[le]&255)|0,D[le]=ee&255,ee>>>=8;g-=64,A+=64}if(g>0)for(q(W,D,_,$),le=0;le<g;le++)m[A+le]=W[le];return 0}function b(m,A,g,d,_){var D=new Uint8Array(32);C(D,d,_,$);for(var W=new Uint8Array(8),ee=0;ee<8;ee++)W[ee]=d[ee+16];return v(m,A,g,W,D)}function w(m,A,g,d,_,D,W){var ee=new Uint8Array(32);C(ee,D,W,$);for(var le=new Uint8Array(8),Ee=0;Ee<8;Ee++)le[Ee]=D[Ee+16];return F(m,A,g,d,_,le,ee)}var k=function(m){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,g,d,_,D,W,ee,le;A=m[0]&255|(m[1]&255)<<8,this.r[0]=A&8191,g=m[2]&255|(m[3]&255)<<8,this.r[1]=(A>>>13|g<<3)&8191,d=m[4]&255|(m[5]&255)<<8,this.r[2]=(g>>>10|d<<6)&7939,_=m[6]&255|(m[7]&255)<<8,this.r[3]=(d>>>7|_<<9)&8191,D=m[8]&255|(m[9]&255)<<8,this.r[4]=(_>>>4|D<<12)&255,this.r[5]=D>>>1&8190,W=m[10]&255|(m[11]&255)<<8,this.r[6]=(D>>>14|W<<2)&8191,ee=m[12]&255|(m[13]&255)<<8,this.r[7]=(W>>>11|ee<<5)&8065,le=m[14]&255|(m[15]&255)<<8,this.r[8]=(ee>>>8|le<<8)&8191,this.r[9]=le>>>5&127,this.pad[0]=m[16]&255|(m[17]&255)<<8,this.pad[1]=m[18]&255|(m[19]&255)<<8,this.pad[2]=m[20]&255|(m[21]&255)<<8,this.pad[3]=m[22]&255|(m[23]&255)<<8,this.pad[4]=m[24]&255|(m[25]&255)<<8,this.pad[5]=m[26]&255|(m[27]&255)<<8,this.pad[6]=m[28]&255|(m[29]&255)<<8,this.pad[7]=m[30]&255|(m[31]&255)<<8};k.prototype.blocks=function(m,A,g){for(var d=this.fin?0:2048,_,D,W,ee,le,Ee,ge,it,ye,Me,Le,Qe,He,De,$e,Ue,_e,xe,Ae,be=this.h[0],Se=this.h[1],me=this.h[2],K=this.h[3],V=this.h[4],se=this.h[5],Z=this.h[6],te=this.h[7],ce=this.h[8],ve=this.h[9],We=this.r[0],Ke=this.r[1],qe=this.r[2],I=this.r[3],ze=this.r[4],st=this.r[5],ot=this.r[6],Ve=this.r[7],et=this.r[8],tt=this.r[9];g>=16;)_=m[A+0]&255|(m[A+1]&255)<<8,be+=_&8191,D=m[A+2]&255|(m[A+3]&255)<<8,Se+=(_>>>13|D<<3)&8191,W=m[A+4]&255|(m[A+5]&255)<<8,me+=(D>>>10|W<<6)&8191,ee=m[A+6]&255|(m[A+7]&255)<<8,K+=(W>>>7|ee<<9)&8191,le=m[A+8]&255|(m[A+9]&255)<<8,V+=(ee>>>4|le<<12)&8191,se+=le>>>1&8191,Ee=m[A+10]&255|(m[A+11]&255)<<8,Z+=(le>>>14|Ee<<2)&8191,ge=m[A+12]&255|(m[A+13]&255)<<8,te+=(Ee>>>11|ge<<5)&8191,it=m[A+14]&255|(m[A+15]&255)<<8,ce+=(ge>>>8|it<<8)&8191,ve+=it>>>5|d,ye=0,Me=ye,Me+=be*We,Me+=Se*(5*tt),Me+=me*(5*et),Me+=K*(5*Ve),Me+=V*(5*ot),ye=Me>>>13,Me&=8191,Me+=se*(5*st),Me+=Z*(5*ze),Me+=te*(5*I),Me+=ce*(5*qe),Me+=ve*(5*Ke),ye+=Me>>>13,Me&=8191,Le=ye,Le+=be*Ke,Le+=Se*We,Le+=me*(5*tt),Le+=K*(5*et),Le+=V*(5*Ve),ye=Le>>>13,Le&=8191,Le+=se*(5*ot),Le+=Z*(5*st),Le+=te*(5*ze),Le+=ce*(5*I),Le+=ve*(5*qe),ye+=Le>>>13,Le&=8191,Qe=ye,Qe+=be*qe,Qe+=Se*Ke,Qe+=me*We,Qe+=K*(5*tt),Qe+=V*(5*et),ye=Qe>>>13,Qe&=8191,Qe+=se*(5*Ve),Qe+=Z*(5*ot),Qe+=te*(5*st),Qe+=ce*(5*ze),Qe+=ve*(5*I),ye+=Qe>>>13,Qe&=8191,He=ye,He+=be*I,He+=Se*qe,He+=me*Ke,He+=K*We,He+=V*(5*tt),ye=He>>>13,He&=8191,He+=se*(5*et),He+=Z*(5*Ve),He+=te*(5*ot),He+=ce*(5*st),He+=ve*(5*ze),ye+=He>>>13,He&=8191,De=ye,De+=be*ze,De+=Se*I,De+=me*qe,De+=K*Ke,De+=V*We,ye=De>>>13,De&=8191,De+=se*(5*tt),De+=Z*(5*et),De+=te*(5*Ve),De+=ce*(5*ot),De+=ve*(5*st),ye+=De>>>13,De&=8191,$e=ye,$e+=be*st,$e+=Se*ze,$e+=me*I,$e+=K*qe,$e+=V*Ke,ye=$e>>>13,$e&=8191,$e+=se*We,$e+=Z*(5*tt),$e+=te*(5*et),$e+=ce*(5*Ve),$e+=ve*(5*ot),ye+=$e>>>13,$e&=8191,Ue=ye,Ue+=be*ot,Ue+=Se*st,Ue+=me*ze,Ue+=K*I,Ue+=V*qe,ye=Ue>>>13,Ue&=8191,Ue+=se*Ke,Ue+=Z*We,Ue+=te*(5*tt),Ue+=ce*(5*et),Ue+=ve*(5*Ve),ye+=Ue>>>13,Ue&=8191,_e=ye,_e+=be*Ve,_e+=Se*ot,_e+=me*st,_e+=K*ze,_e+=V*I,ye=_e>>>13,_e&=8191,_e+=se*qe,_e+=Z*Ke,_e+=te*We,_e+=ce*(5*tt),_e+=ve*(5*et),ye+=_e>>>13,_e&=8191,xe=ye,xe+=be*et,xe+=Se*Ve,xe+=me*ot,xe+=K*st,xe+=V*ze,ye=xe>>>13,xe&=8191,xe+=se*I,xe+=Z*qe,xe+=te*Ke,xe+=ce*We,xe+=ve*(5*tt),ye+=xe>>>13,xe&=8191,Ae=ye,Ae+=be*tt,Ae+=Se*et,Ae+=me*Ve,Ae+=K*ot,Ae+=V*st,ye=Ae>>>13,Ae&=8191,Ae+=se*ze,Ae+=Z*I,Ae+=te*qe,Ae+=ce*Ke,Ae+=ve*We,ye+=Ae>>>13,Ae&=8191,ye=(ye<<2)+ye|0,ye=ye+Me|0,Me=ye&8191,ye=ye>>>13,Le+=ye,be=Me,Se=Le,me=Qe,K=He,V=De,se=$e,Z=Ue,te=_e,ce=xe,ve=Ae,A+=16,g-=16;this.h[0]=be,this.h[1]=Se,this.h[2]=me,this.h[3]=K,this.h[4]=V,this.h[5]=se,this.h[6]=Z,this.h[7]=te,this.h[8]=ce,this.h[9]=ve},k.prototype.finish=function(m,A){var g=new Uint16Array(10),d,_,D,W;if(this.leftover){for(W=this.leftover,this.buffer[W++]=1;W<16;W++)this.buffer[W]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(d=this.h[1]>>>13,this.h[1]&=8191,W=2;W<10;W++)this.h[W]+=d,d=this.h[W]>>>13,this.h[W]&=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,g[0]=this.h[0]+5,d=g[0]>>>13,g[0]&=8191,W=1;W<10;W++)g[W]=this.h[W]+d,d=g[W]>>>13,g[W]&=8191;for(g[9]-=8192,_=(d^1)-1,W=0;W<10;W++)g[W]&=_;for(_=~_,W=0;W<10;W++)this.h[W]=this.h[W]&_|g[W];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,D=this.h[0]+this.pad[0],this.h[0]=D&65535,W=1;W<8;W++)D=(this.h[W]+this.pad[W]|0)+(D>>>16)|0,this.h[W]=D&65535;m[A+0]=this.h[0]>>>0&255,m[A+1]=this.h[0]>>>8&255,m[A+2]=this.h[1]>>>0&255,m[A+3]=this.h[1]>>>8&255,m[A+4]=this.h[2]>>>0&255,m[A+5]=this.h[2]>>>8&255,m[A+6]=this.h[3]>>>0&255,m[A+7]=this.h[3]>>>8&255,m[A+8]=this.h[4]>>>0&255,m[A+9]=this.h[4]>>>8&255,m[A+10]=this.h[5]>>>0&255,m[A+11]=this.h[5]>>>8&255,m[A+12]=this.h[6]>>>0&255,m[A+13]=this.h[6]>>>8&255,m[A+14]=this.h[7]>>>0&255,m[A+15]=this.h[7]>>>8&255},k.prototype.update=function(m,A,g){var d,_;if(this.leftover){for(_=16-this.leftover,_>g&&(_=g),d=0;d<_;d++)this.buffer[this.leftover+d]=m[A+d];if(g-=_,A+=_,this.leftover+=_,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(g>=16&&(_=g-g%16,this.blocks(m,A,_),A+=_,g-=_),g){for(d=0;d<g;d++)this.buffer[this.leftover+d]=m[A+d];this.leftover+=g}};function N(m,A,g,d,_,D){var W=new k(D);return W.update(g,d,_),W.finish(m,A),0}function R(m,A,g,d,_,D){var W=new Uint8Array(16);return N(W,0,g,d,_,D),E(m,A,W,0)}function ie(m,A,g,d,_){var D;if(g<32)return-1;for(w(m,0,A,0,g,d,_),N(m,16,m,32,g-32,m),D=0;D<16;D++)m[D]=0;return 0}function j(m,A,g,d,_){var D,W=new Uint8Array(32);if(g<32||(b(W,0,32,d,_),R(A,16,A,32,g-32,W)!==0))return-1;for(w(m,0,A,0,g,d,_),D=0;D<32;D++)m[D]=0;return 0}function X(m,A){var g;for(g=0;g<16;g++)m[g]=A[g]|0}function re(m){var A,g,d=1;for(A=0;A<16;A++)g=m[A]+d+65535,d=Math.floor(g/65536),m[A]=g-d*65536;m[0]+=d-1+37*(d-1)}function fe(m,A,g){for(var d,_=~(g-1),D=0;D<16;D++)d=_&(m[D]^A[D]),m[D]^=d,A[D]^=d}function H(m,A){var g,d,_,D=t(),W=t();for(g=0;g<16;g++)W[g]=A[g];for(re(W),re(W),re(W),d=0;d<2;d++){for(D[0]=W[0]-65517,g=1;g<15;g++)D[g]=W[g]-65535-(D[g-1]>>16&1),D[g-1]&=65535;D[15]=W[15]-32767-(D[14]>>16&1),_=D[15]>>16&1,D[14]&=65535,fe(W,D,1-_)}for(g=0;g<16;g++)m[2*g]=W[g]&255,m[2*g+1]=W[g]>>8}function B(m,A){var g=new Uint8Array(32),d=new Uint8Array(32);return H(g,m),H(d,A),S(g,0,d,0)}function L(m){var A=new Uint8Array(32);return H(A,m),A[0]&1}function z(m,A){var g;for(g=0;g<16;g++)m[g]=A[2*g]+(A[2*g+1]<<8);m[15]&=32767}function ne(m,A,g){for(var d=0;d<16;d++)m[d]=A[d]+g[d]}function de(m,A,g){for(var d=0;d<16;d++)m[d]=A[d]-g[d]}function oe(m,A,g){var d,_,D=0,W=0,ee=0,le=0,Ee=0,ge=0,it=0,ye=0,Me=0,Le=0,Qe=0,He=0,De=0,$e=0,Ue=0,_e=0,xe=0,Ae=0,be=0,Se=0,me=0,K=0,V=0,se=0,Z=0,te=0,ce=0,ve=0,We=0,Ke=0,qe=0,I=g[0],ze=g[1],st=g[2],ot=g[3],Ve=g[4],et=g[5],tt=g[6],Rt=g[7],ht=g[8],vt=g[9],Nt=g[10],Bt=g[11],$t=g[12],Vt=g[13],zt=g[14],Gt=g[15];d=A[0],D+=d*I,W+=d*ze,ee+=d*st,le+=d*ot,Ee+=d*Ve,ge+=d*et,it+=d*tt,ye+=d*Rt,Me+=d*ht,Le+=d*vt,Qe+=d*Nt,He+=d*Bt,De+=d*$t,$e+=d*Vt,Ue+=d*zt,_e+=d*Gt,d=A[1],W+=d*I,ee+=d*ze,le+=d*st,Ee+=d*ot,ge+=d*Ve,it+=d*et,ye+=d*tt,Me+=d*Rt,Le+=d*ht,Qe+=d*vt,He+=d*Nt,De+=d*Bt,$e+=d*$t,Ue+=d*Vt,_e+=d*zt,xe+=d*Gt,d=A[2],ee+=d*I,le+=d*ze,Ee+=d*st,ge+=d*ot,it+=d*Ve,ye+=d*et,Me+=d*tt,Le+=d*Rt,Qe+=d*ht,He+=d*vt,De+=d*Nt,$e+=d*Bt,Ue+=d*$t,_e+=d*Vt,xe+=d*zt,Ae+=d*Gt,d=A[3],le+=d*I,Ee+=d*ze,ge+=d*st,it+=d*ot,ye+=d*Ve,Me+=d*et,Le+=d*tt,Qe+=d*Rt,He+=d*ht,De+=d*vt,$e+=d*Nt,Ue+=d*Bt,_e+=d*$t,xe+=d*Vt,Ae+=d*zt,be+=d*Gt,d=A[4],Ee+=d*I,ge+=d*ze,it+=d*st,ye+=d*ot,Me+=d*Ve,Le+=d*et,Qe+=d*tt,He+=d*Rt,De+=d*ht,$e+=d*vt,Ue+=d*Nt,_e+=d*Bt,xe+=d*$t,Ae+=d*Vt,be+=d*zt,Se+=d*Gt,d=A[5],ge+=d*I,it+=d*ze,ye+=d*st,Me+=d*ot,Le+=d*Ve,Qe+=d*et,He+=d*tt,De+=d*Rt,$e+=d*ht,Ue+=d*vt,_e+=d*Nt,xe+=d*Bt,Ae+=d*$t,be+=d*Vt,Se+=d*zt,me+=d*Gt,d=A[6],it+=d*I,ye+=d*ze,Me+=d*st,Le+=d*ot,Qe+=d*Ve,He+=d*et,De+=d*tt,$e+=d*Rt,Ue+=d*ht,_e+=d*vt,xe+=d*Nt,Ae+=d*Bt,be+=d*$t,Se+=d*Vt,me+=d*zt,K+=d*Gt,d=A[7],ye+=d*I,Me+=d*ze,Le+=d*st,Qe+=d*ot,He+=d*Ve,De+=d*et,$e+=d*tt,Ue+=d*Rt,_e+=d*ht,xe+=d*vt,Ae+=d*Nt,be+=d*Bt,Se+=d*$t,me+=d*Vt,K+=d*zt,V+=d*Gt,d=A[8],Me+=d*I,Le+=d*ze,Qe+=d*st,He+=d*ot,De+=d*Ve,$e+=d*et,Ue+=d*tt,_e+=d*Rt,xe+=d*ht,Ae+=d*vt,be+=d*Nt,Se+=d*Bt,me+=d*$t,K+=d*Vt,V+=d*zt,se+=d*Gt,d=A[9],Le+=d*I,Qe+=d*ze,He+=d*st,De+=d*ot,$e+=d*Ve,Ue+=d*et,_e+=d*tt,xe+=d*Rt,Ae+=d*ht,be+=d*vt,Se+=d*Nt,me+=d*Bt,K+=d*$t,V+=d*Vt,se+=d*zt,Z+=d*Gt,d=A[10],Qe+=d*I,He+=d*ze,De+=d*st,$e+=d*ot,Ue+=d*Ve,_e+=d*et,xe+=d*tt,Ae+=d*Rt,be+=d*ht,Se+=d*vt,me+=d*Nt,K+=d*Bt,V+=d*$t,se+=d*Vt,Z+=d*zt,te+=d*Gt,d=A[11],He+=d*I,De+=d*ze,$e+=d*st,Ue+=d*ot,_e+=d*Ve,xe+=d*et,Ae+=d*tt,be+=d*Rt,Se+=d*ht,me+=d*vt,K+=d*Nt,V+=d*Bt,se+=d*$t,Z+=d*Vt,te+=d*zt,ce+=d*Gt,d=A[12],De+=d*I,$e+=d*ze,Ue+=d*st,_e+=d*ot,xe+=d*Ve,Ae+=d*et,be+=d*tt,Se+=d*Rt,me+=d*ht,K+=d*vt,V+=d*Nt,se+=d*Bt,Z+=d*$t,te+=d*Vt,ce+=d*zt,ve+=d*Gt,d=A[13],$e+=d*I,Ue+=d*ze,_e+=d*st,xe+=d*ot,Ae+=d*Ve,be+=d*et,Se+=d*tt,me+=d*Rt,K+=d*ht,V+=d*vt,se+=d*Nt,Z+=d*Bt,te+=d*$t,ce+=d*Vt,ve+=d*zt,We+=d*Gt,d=A[14],Ue+=d*I,_e+=d*ze,xe+=d*st,Ae+=d*ot,be+=d*Ve,Se+=d*et,me+=d*tt,K+=d*Rt,V+=d*ht,se+=d*vt,Z+=d*Nt,te+=d*Bt,ce+=d*$t,ve+=d*Vt,We+=d*zt,Ke+=d*Gt,d=A[15],_e+=d*I,xe+=d*ze,Ae+=d*st,be+=d*ot,Se+=d*Ve,me+=d*et,K+=d*tt,V+=d*Rt,se+=d*ht,Z+=d*vt,te+=d*Nt,ce+=d*Bt,ve+=d*$t,We+=d*Vt,Ke+=d*zt,qe+=d*Gt,D+=38*xe,W+=38*Ae,ee+=38*be,le+=38*Se,Ee+=38*me,ge+=38*K,it+=38*V,ye+=38*se,Me+=38*Z,Le+=38*te,Qe+=38*ce,He+=38*ve,De+=38*We,$e+=38*Ke,Ue+=38*qe,_=1,d=D+_+65535,_=Math.floor(d/65536),D=d-_*65536,d=W+_+65535,_=Math.floor(d/65536),W=d-_*65536,d=ee+_+65535,_=Math.floor(d/65536),ee=d-_*65536,d=le+_+65535,_=Math.floor(d/65536),le=d-_*65536,d=Ee+_+65535,_=Math.floor(d/65536),Ee=d-_*65536,d=ge+_+65535,_=Math.floor(d/65536),ge=d-_*65536,d=it+_+65535,_=Math.floor(d/65536),it=d-_*65536,d=ye+_+65535,_=Math.floor(d/65536),ye=d-_*65536,d=Me+_+65535,_=Math.floor(d/65536),Me=d-_*65536,d=Le+_+65535,_=Math.floor(d/65536),Le=d-_*65536,d=Qe+_+65535,_=Math.floor(d/65536),Qe=d-_*65536,d=He+_+65535,_=Math.floor(d/65536),He=d-_*65536,d=De+_+65535,_=Math.floor(d/65536),De=d-_*65536,d=$e+_+65535,_=Math.floor(d/65536),$e=d-_*65536,d=Ue+_+65535,_=Math.floor(d/65536),Ue=d-_*65536,d=_e+_+65535,_=Math.floor(d/65536),_e=d-_*65536,D+=_-1+37*(_-1),_=1,d=D+_+65535,_=Math.floor(d/65536),D=d-_*65536,d=W+_+65535,_=Math.floor(d/65536),W=d-_*65536,d=ee+_+65535,_=Math.floor(d/65536),ee=d-_*65536,d=le+_+65535,_=Math.floor(d/65536),le=d-_*65536,d=Ee+_+65535,_=Math.floor(d/65536),Ee=d-_*65536,d=ge+_+65535,_=Math.floor(d/65536),ge=d-_*65536,d=it+_+65535,_=Math.floor(d/65536),it=d-_*65536,d=ye+_+65535,_=Math.floor(d/65536),ye=d-_*65536,d=Me+_+65535,_=Math.floor(d/65536),Me=d-_*65536,d=Le+_+65535,_=Math.floor(d/65536),Le=d-_*65536,d=Qe+_+65535,_=Math.floor(d/65536),Qe=d-_*65536,d=He+_+65535,_=Math.floor(d/65536),He=d-_*65536,d=De+_+65535,_=Math.floor(d/65536),De=d-_*65536,d=$e+_+65535,_=Math.floor(d/65536),$e=d-_*65536,d=Ue+_+65535,_=Math.floor(d/65536),Ue=d-_*65536,d=_e+_+65535,_=Math.floor(d/65536),_e=d-_*65536,D+=_-1+37*(_-1),m[0]=D,m[1]=W,m[2]=ee,m[3]=le,m[4]=Ee,m[5]=ge,m[6]=it,m[7]=ye,m[8]=Me,m[9]=Le,m[10]=Qe,m[11]=He,m[12]=De,m[13]=$e,m[14]=Ue,m[15]=_e}function Xe(m,A){oe(m,A,A)}function dt(m,A){var g=t(),d;for(d=0;d<16;d++)g[d]=A[d];for(d=253;d>=0;d--)Xe(g,g),d!==2&&d!==4&&oe(g,g,A);for(d=0;d<16;d++)m[d]=g[d]}function cn(m,A){var g=t(),d;for(d=0;d<16;d++)g[d]=A[d];for(d=250;d>=0;d--)Xe(g,g),d!==1&&oe(g,g,A);for(d=0;d<16;d++)m[d]=g[d]}function br(m,A,g){var d=new Uint8Array(32),_=new Float64Array(80),D,W,ee=t(),le=t(),Ee=t(),ge=t(),it=t(),ye=t();for(W=0;W<31;W++)d[W]=A[W];for(d[31]=A[31]&127|64,d[0]&=248,z(_,g),W=0;W<16;W++)le[W]=_[W],ge[W]=ee[W]=Ee[W]=0;for(ee[0]=ge[0]=1,W=254;W>=0;--W)D=d[W>>>3]>>>(W&7)&1,fe(ee,le,D),fe(Ee,ge,D),ne(it,ee,Ee),de(ee,ee,Ee),ne(Ee,le,ge),de(le,le,ge),Xe(ge,it),Xe(ye,ee),oe(ee,Ee,ee),oe(Ee,le,it),ne(it,ee,Ee),de(ee,ee,Ee),Xe(le,ee),de(Ee,ge,ye),oe(ee,Ee,a),ne(ee,ee,ge),oe(Ee,Ee,ee),oe(ee,ge,ye),oe(ge,le,_),Xe(le,it),fe(ee,le,D),fe(Ee,ge,D);for(W=0;W<16;W++)_[W+16]=ee[W],_[W+32]=Ee[W],_[W+48]=le[W],_[W+64]=ge[W];var Me=_.subarray(32),Le=_.subarray(16);return dt(Me,Me),oe(Le,Le,Me),H(m,Le),0}function Sr(m,A){return br(m,A,s)}function On(m,A){return e(A,32),Sr(m,A)}function xr(m,A,g){var d=new Uint8Array(32);return br(d,g,A),C(m,r,d,$)}var ri=ie,zi=j;function ii(m,A,g,d,_,D){var W=new Uint8Array(32);return xr(W,_,D),ri(m,A,g,d,W)}function wr(m,A,g,d,_,D){var W=new Uint8Array(32);return xr(W,_,D),zi(m,A,g,d,W)}var Ir=[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(m,A,g,d){for(var _=new Int32Array(16),D=new Int32Array(16),W,ee,le,Ee,ge,it,ye,Me,Le,Qe,He,De,$e,Ue,_e,xe,Ae,be,Se,me,K,V,se,Z,te,ce,ve=m[0],We=m[1],Ke=m[2],qe=m[3],I=m[4],ze=m[5],st=m[6],ot=m[7],Ve=A[0],et=A[1],tt=A[2],Rt=A[3],ht=A[4],vt=A[5],Nt=A[6],Bt=A[7],$t=0;d>=128;){for(Se=0;Se<16;Se++)me=8*Se+$t,_[Se]=g[me+0]<<24|g[me+1]<<16|g[me+2]<<8|g[me+3],D[Se]=g[me+4]<<24|g[me+5]<<16|g[me+6]<<8|g[me+7];for(Se=0;Se<80;Se++)if(W=ve,ee=We,le=Ke,Ee=qe,ge=I,it=ze,ye=st,Me=ot,Le=Ve,Qe=et,He=tt,De=Rt,$e=ht,Ue=vt,_e=Nt,xe=Bt,K=ot,V=Bt,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=(I>>>14|ht<<18)^(I>>>18|ht<<14)^(ht>>>9|I<<23),V=(ht>>>14|I<<18)^(ht>>>18|I<<14)^(I>>>9|ht<<23),se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,K=I&ze^~I&st,V=ht&vt^~ht&Nt,se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,K=Ir[Se*2],V=Ir[Se*2+1],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,K=_[Se%16],V=D[Se%16],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,Ae=te&65535|ce<<16,be=se&65535|Z<<16,K=Ae,V=be,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=(ve>>>28|Ve<<4)^(Ve>>>2|ve<<30)^(Ve>>>7|ve<<25),V=(Ve>>>28|ve<<4)^(ve>>>2|Ve<<30)^(ve>>>7|Ve<<25),se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,K=ve&We^ve&Ke^We&Ke,V=Ve&et^Ve&tt^et&tt,se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,Me=te&65535|ce<<16,xe=se&65535|Z<<16,K=Ee,V=De,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=Ae,V=be,se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,Ee=te&65535|ce<<16,De=se&65535|Z<<16,We=W,Ke=ee,qe=le,I=Ee,ze=ge,st=it,ot=ye,ve=Me,et=Le,tt=Qe,Rt=He,ht=De,vt=$e,Nt=Ue,Bt=_e,Ve=xe,Se%16===15)for(me=0;me<16;me++)K=_[me],V=D[me],se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=_[(me+9)%16],V=D[(me+9)%16],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Ae=_[(me+1)%16],be=D[(me+1)%16],K=(Ae>>>1|be<<31)^(Ae>>>8|be<<24)^Ae>>>7,V=(be>>>1|Ae<<31)^(be>>>8|Ae<<24)^(be>>>7|Ae<<25),se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Ae=_[(me+14)%16],be=D[(me+14)%16],K=(Ae>>>19|be<<13)^(be>>>29|Ae<<3)^Ae>>>6,V=(be>>>19|Ae<<13)^(Ae>>>29|be<<3)^(be>>>6|Ae<<26),se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,_[me]=te&65535|ce<<16,D[me]=se&65535|Z<<16;K=ve,V=Ve,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[0],V=A[0],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[0]=ve=te&65535|ce<<16,A[0]=Ve=se&65535|Z<<16,K=We,V=et,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[1],V=A[1],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[1]=We=te&65535|ce<<16,A[1]=et=se&65535|Z<<16,K=Ke,V=tt,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[2],V=A[2],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[2]=Ke=te&65535|ce<<16,A[2]=tt=se&65535|Z<<16,K=qe,V=Rt,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[3],V=A[3],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[3]=qe=te&65535|ce<<16,A[3]=Rt=se&65535|Z<<16,K=I,V=ht,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[4],V=A[4],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[4]=I=te&65535|ce<<16,A[4]=ht=se&65535|Z<<16,K=ze,V=vt,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[5],V=A[5],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[5]=ze=te&65535|ce<<16,A[5]=vt=se&65535|Z<<16,K=st,V=Nt,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[6],V=A[6],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[6]=st=te&65535|ce<<16,A[6]=Nt=se&65535|Z<<16,K=ot,V=Bt,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[7],V=A[7],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[7]=ot=te&65535|ce<<16,A[7]=Bt=se&65535|Z<<16,$t+=128,d-=128}return d}function pe(m,A,g){var d=new Int32Array(8),_=new Int32Array(8),D=new Uint8Array(256),W,ee=g;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,_,A,g),g%=128,W=0;W<g;W++)D[W]=A[ee-g+W];for(D[g]=128,g=256-128*(g<112?1:0),D[g-9]=0,p(D,g-8,ee/536870912|0,ee<<3),J(d,_,D,g),W=0;W<8;W++)p(m,8*W,d[W],_[W]);return 0}function we(m,A){var g=t(),d=t(),_=t(),D=t(),W=t(),ee=t(),le=t(),Ee=t(),ge=t();de(g,m[1],m[0]),de(ge,A[1],A[0]),oe(g,g,ge),ne(d,m[0],m[1]),ne(ge,A[0],A[1]),oe(d,d,ge),oe(_,m[3],A[3]),oe(_,_,l),oe(D,m[2],A[2]),ne(D,D,D),de(W,d,g),de(ee,D,_),ne(le,D,_),ne(Ee,d,g),oe(m[0],W,ee),oe(m[1],Ee,le),oe(m[2],le,ee),oe(m[3],W,Ee)}function Oe(m,A,g){var d;for(d=0;d<4;d++)fe(m[d],A[d],g)}function Je(m,A){var g=t(),d=t(),_=t();dt(_,A[2]),oe(g,A[0],_),oe(d,A[1],_),H(m,d),m[31]^=L(g)<<7}function Lt(m,A,g){var d,_;for(X(m[0],i),X(m[1],o),X(m[2],o),X(m[3],i),_=255;_>=0;--_)d=g[_/8|0]>>(_&7)&1,Oe(m,A,d),we(A,m),we(m,m),Oe(m,A,d)}function Cn(m,A){var g=[t(),t(),t(),t()];X(g[0],u),X(g[1],f),X(g[2],o),oe(g[3],u,f),Lt(m,g,A)}function ln(m,A,g){var d=new Uint8Array(64),_=[t(),t(),t(),t()],D;for(g||e(A,32),pe(d,A,32),d[0]&=248,d[31]&=127,d[31]|=64,Cn(_,d),Je(m,_),D=0;D<32;D++)A[D+32]=m[D];return 0}var Cr=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 ct(m,A){var g,d,_,D;for(d=63;d>=32;--d){for(g=0,_=d-32,D=d-12;_<D;++_)A[_]+=g-16*A[d]*Cr[_-(d-32)],g=A[_]+128>>8,A[_]-=g*256;A[_]+=g,A[d]=0}for(g=0,_=0;_<32;_++)A[_]+=g-(A[31]>>4)*Cr[_],g=A[_]>>8,A[_]&=255;for(_=0;_<32;_++)A[_]-=g*Cr[_];for(d=0;d<32;d++)A[d+1]+=A[d]>>8,m[d]=A[d]&255}function Ft(m){var A=new Float64Array(64),g;for(g=0;g<64;g++)A[g]=m[g];for(g=0;g<64;g++)m[g]=0;ct(m,A)}function Ut(m,A,g,d){var _=new Uint8Array(64),D=new Uint8Array(64),W=new Uint8Array(64),ee,le,Ee=new Float64Array(64),ge=[t(),t(),t(),t()];pe(_,d,32),_[0]&=248,_[31]&=127,_[31]|=64;var it=g+64;for(ee=0;ee<g;ee++)m[64+ee]=A[ee];for(ee=0;ee<32;ee++)m[32+ee]=_[32+ee];for(pe(W,m.subarray(32),g+32),Ft(W),Cn(ge,W),Je(m,ge),ee=32;ee<64;ee++)m[ee]=d[ee];for(pe(D,m,g+64),Ft(D),ee=0;ee<64;ee++)Ee[ee]=0;for(ee=0;ee<32;ee++)Ee[ee]=W[ee];for(ee=0;ee<32;ee++)for(le=0;le<32;le++)Ee[ee+le]+=D[ee]*_[le];return ct(m.subarray(32),Ee),it}function Ct(m,A){var g=t(),d=t(),_=t(),D=t(),W=t(),ee=t(),le=t();return X(m[2],o),z(m[1],A),Xe(_,m[1]),oe(D,_,c),de(_,_,m[2]),ne(D,m[2],D),Xe(W,D),Xe(ee,W),oe(le,ee,W),oe(g,le,_),oe(g,g,D),cn(g,g),oe(g,g,_),oe(g,g,D),oe(g,g,D),oe(m[0],g,D),Xe(d,m[0]),oe(d,d,D),B(d,_)&&oe(m[0],m[0],h),Xe(d,m[0]),oe(d,d,D),B(d,_)?-1:(L(m[0])===A[31]>>7&&de(m[0],i,m[0]),oe(m[3],m[0],m[1]),0)}function gt(m,A,g,d){var _,D,W=new Uint8Array(32),ee=new Uint8Array(64),le=[t(),t(),t(),t()],Ee=[t(),t(),t(),t()];if(D=-1,g<64||Ct(Ee,d))return-1;for(_=0;_<g;_++)m[_]=A[_];for(_=0;_<32;_++)m[_+32]=d[_];if(pe(ee,m,g),Ft(ee),Lt(le,Ee,ee),Cn(Ee,A.subarray(32)),we(le,Ee),Je(W,le),g-=64,S(A,0,W,0)){for(_=0;_<g;_++)m[_]=0;return-1}for(_=0;_<g;_++)m[_]=A[_+64];return D=g,D}var pn=32,kt=24,lr=32,kr=16,si=32,Gi=32,oi=32,ai=32,ho=32,Oc=kt,lp=lr,up=kr,Mn=64,ur=32,vr=64,po=32,mo=64;n.lowlevel={crypto_core_hsalsa20:C,crypto_stream_xor:w,crypto_stream:b,crypto_stream_salsa20_xor:F,crypto_stream_salsa20:v,crypto_onetimeauth:N,crypto_onetimeauth_verify:R,crypto_verify_16:E,crypto_verify_32:S,crypto_secretbox:ie,crypto_secretbox_open:j,crypto_scalarmult:br,crypto_scalarmult_base:Sr,crypto_box_beforenm:xr,crypto_box_afternm:ri,crypto_box:ii,crypto_box_open:wr,crypto_box_keypair:On,crypto_hash:pe,crypto_sign:Ut,crypto_sign_keypair:ln,crypto_sign_open:gt,crypto_secretbox_KEYBYTES:pn,crypto_secretbox_NONCEBYTES:kt,crypto_secretbox_ZEROBYTES:lr,crypto_secretbox_BOXZEROBYTES:kr,crypto_scalarmult_BYTES:si,crypto_scalarmult_SCALARBYTES:Gi,crypto_box_PUBLICKEYBYTES:oi,crypto_box_SECRETKEYBYTES:ai,crypto_box_BEFORENMBYTES:ho,crypto_box_NONCEBYTES:Oc,crypto_box_ZEROBYTES:lp,crypto_box_BOXZEROBYTES:up,crypto_sign_BYTES:Mn,crypto_sign_PUBLICKEYBYTES:ur,crypto_sign_SECRETKEYBYTES:vr,crypto_sign_SEEDBYTES:po,crypto_hash_BYTES:mo};function Mc(m,A){if(m.length!==pn)throw new Error("bad key size");if(A.length!==kt)throw new Error("bad nonce size")}function fp(m,A){if(m.length!==oi)throw new Error("bad public key size");if(A.length!==ai)throw new Error("bad secret key size")}function un(){var m,A;for(A=0;A<arguments.length;A++)if((m=Object.prototype.toString.call(arguments[A]))!=="[object Uint8Array]")throw new TypeError("unexpected type "+m+", use Uint8Array")}function Lc(m){for(var A=0;A<m.length;A++)m[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(m){var A=new Uint8Array(m);return e(A,m),A},n.secretbox=function(m,A,g){un(m,A,g),Mc(g,A);for(var d=new Uint8Array(lr+m.length),_=new Uint8Array(d.length),D=0;D<m.length;D++)d[D+lr]=m[D];return ie(_,d,d.length,A,g),_.subarray(kr)},n.secretbox.open=function(m,A,g){un(m,A,g),Mc(g,A);for(var d=new Uint8Array(kr+m.length),_=new Uint8Array(d.length),D=0;D<m.length;D++)d[D+kr]=m[D];return d.length<32||j(_,d,d.length,A,g)!==0?!1:_.subarray(lr)},n.secretbox.keyLength=pn,n.secretbox.nonceLength=kt,n.secretbox.overheadLength=kr,n.scalarMult=function(m,A){if(un(m,A),m.length!==Gi)throw new Error("bad n size");if(A.length!==si)throw new Error("bad p size");var g=new Uint8Array(si);return br(g,m,A),g},n.scalarMult.base=function(m){if(un(m),m.length!==Gi)throw new Error("bad n size");var A=new Uint8Array(si);return Sr(A,m),A},n.scalarMult.scalarLength=Gi,n.scalarMult.groupElementLength=si,n.box=function(m,A,g,d){var _=n.box.before(g,d);return n.secretbox(m,A,_)},n.box.before=function(m,A){un(m,A),fp(m,A);var g=new Uint8Array(ho);return xr(g,m,A),g},n.box.after=n.secretbox,n.box.open=function(m,A,g,d){var _=n.box.before(g,d);return n.secretbox.open(m,A,_)},n.box.open.after=n.secretbox.open,n.box.keyPair=function(){var m=new Uint8Array(oi),A=new Uint8Array(ai);return On(m,A),{publicKey:m,secretKey:A}},n.box.keyPair.fromSecretKey=function(m){if(un(m),m.length!==ai)throw new Error("bad secret key size");var A=new Uint8Array(oi);return Sr(A,m),{publicKey:A,secretKey:new Uint8Array(m)}},n.box.publicKeyLength=oi,n.box.secretKeyLength=ai,n.box.sharedKeyLength=ho,n.box.nonceLength=Oc,n.box.overheadLength=n.secretbox.overheadLength,n.sign=function(m,A){if(un(m,A),A.length!==vr)throw new Error("bad secret key size");var g=new Uint8Array(Mn+m.length);return Ut(g,m,m.length,A),g},n.sign.open=function(m,A){if(arguments.length!==2)throw new Error("nacl.sign.open accepts 2 arguments; did you mean to use nacl.sign.detached.verify?");if(un(m,A),A.length!==ur)throw new Error("bad public key size");var g=new Uint8Array(m.length),d=gt(g,m,m.length,A);if(d<0)return null;for(var _=new Uint8Array(d),D=0;D<_.length;D++)_[D]=g[D];return _},n.sign.detached=function(m,A){for(var g=n.sign(m,A),d=new Uint8Array(Mn),_=0;_<d.length;_++)d[_]=g[_];return d},n.sign.detached.verify=function(m,A,g){if(un(m,A,g),A.length!==Mn)throw new Error("bad signature size");if(g.length!==ur)throw new Error("bad public key size");var d=new Uint8Array(Mn+m.length),_=new Uint8Array(Mn+m.length),D;for(D=0;D<Mn;D++)d[D]=A[D];for(D=0;D<m.length;D++)d[D+Mn]=m[D];return gt(_,d,d.length,g)>=0},n.sign.keyPair=function(){var m=new Uint8Array(ur),A=new Uint8Array(vr);return ln(m,A),{publicKey:m,secretKey:A}},n.sign.keyPair.fromSecretKey=function(m){if(un(m),m.length!==vr)throw new Error("bad secret key size");for(var A=new Uint8Array(ur),g=0;g<A.length;g++)A[g]=m[32+g];return{publicKey:A,secretKey:new Uint8Array(m)}},n.sign.keyPair.fromSeed=function(m){if(un(m),m.length!==po)throw new Error("bad seed size");for(var A=new Uint8Array(ur),g=new Uint8Array(vr),d=0;d<32;d++)g[d]=m[d];return ln(A,g,!0),{publicKey:A,secretKey:g}},n.sign.publicKeyLength=ur,n.sign.secretKeyLength=vr,n.sign.seedLength=po,n.sign.signatureLength=Mn,n.hash=function(m){un(m);var A=new Uint8Array(mo);return pe(A,m,m.length),A},n.hash.hashLength=mo,n.verify=function(m,A){return un(m,A),m.length===0||A.length===0||m.length!==A.length?!1:y(m,0,A,0,m.length)===0},n.setPRNG=function(m){e=m},(function(){var m=typeof self<"u"?self.crypto||self.msCrypto:null;if(m&&m.getRandomValues){var A=65536;n.setPRNG(function(g,d){var _,D=new Uint8Array(d);for(_=0;_<d;_+=A)m.getRandomValues(D.subarray(_,_+Math.min(d-_,A)));for(_=0;_<d;_++)g[_]=D[_];Lc(D)})}else typeof require<"u"&&(m=require("crypto"),m&&m.randomBytes&&n.setPRNG(function(g,d){var _,D=m.randomBytes(d);for(_=0;_<d;_++)g[_]=D[_];Lc(D)}))})()})(typeof rs<"u"&&rs.exports?rs.exports:self.nacl=self.nacl||{})});var xo=lt((eE,Yc)=>{"use strict";var _o=Gc().lowlevel.crypto_hash,Ln=0,dr=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 ss(n,t,e){return(n[0][t[e+3]]+n[1][t[e+2]]^n[2][t[e+1]])+n[3][t[e]]}dr.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]^=ss(this.S,t,0)^this.P[e],n[0]^=ss(this.S,t,4)^this.P[e+1];var r=n[0];n[0]=n[1]^this.P[17],n[1]=r};dr.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]^=ss(this.S,t,0)^this.P[e],n[0]^=ss(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++,Ln++)Ln>=t&&(Ln=0),r=r<<8|n[Ln];return r}dr.prototype.expand0state=function(n,t){var e=new Uint32Array(2),r,s,i=new Uint8Array(e.buffer);for(r=0,Ln=0;r<18;r++)this.P[r]^=fr(n,t);for(Ln=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]};dr.prototype.expandstate=function(n,t,e,r){var s=new Uint32Array(2),i,o;for(i=0,Ln=0;i<18;i++)this.P[i]^=fr(e,r);for(i=0,Ln=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];Ln=0};dr.prototype.enc=function(n,t){for(var e=0;e<t;e++)this.encipher(n.subarray(e*2))};dr.prototype.dec=function(n,t){for(var e=0;e<t;e++)this.decipher(n.subarray(e*2))};var is=8,bo=32;function So(n,t,e){var r=new dr,s=new Uint32Array(is),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<is;i++)s[i]=fr(o,o.byteLength);for(i=0;i<64;i++)r.enc(s,s.byteLength/8);for(i=0;i<is;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 Ip(n,t,e,r,s,i,o){var a=new Uint8Array(64),c=new Uint8Array(64),l=new Uint8Array(bo),u=new Uint8Array(bo),f=new Uint8Array(r+4),h,p,y,E,S,x,P=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),y=Math.floor((i+E-1)/E),h=0;h<r;h++)f[h]=e[h];for(_o(a,n,t),x=1;i>0;x++){for(f[r+0]=x>>>24,f[r+1]=x>>>16,f[r+2]=x>>>8,f[r+3]=x,_o(c,f,r+4),So(a,c,u),h=l.byteLength;h--;)l[h]=u[h];for(h=1;h<o;h++)for(_o(c,u,u.byteLength),So(a,c,u),p=0;p<l.byteLength;p++)l[p]^=u[p];for(y=Math.min(y,i),h=0;h<y&&(S=h*E+(x-1),!(S>=P));h++)s[S]=l[h];i-=h}return 0}Yc.exports={BLOCKS:is,HASHSIZE:bo,hash:So,pbkdf:Ip}});var Un=lt((tE,as)=>{"use strict";var Dn=require("crypto"),Tr;try{Tr=require("cpu-features")()}catch{}var{bindingAvailable:jc,CIPHER_INFO:Cp,MAC_INFO:kp}=Gn(),Xc=(()=>{if(typeof Dn.sign=="function"&&typeof Dn.verify=="function"){let n=`-----BEGIN PRIVATE KEY-----\r
2
+ "use strict";var pp=Object.create;var $c=Object.defineProperty;var mp=Object.getOwnPropertyDescriptor;var gp=Object.getOwnPropertyNames;var Ap=Object.getPrototypeOf,yp=Object.prototype.hasOwnProperty;var lt=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var Ep=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of gp(t))!yp.call(n,i)&&i!==e&&$c(n,i,{get:()=>t[i],enumerable:!(r=mp(t,i))||r.enumerable});return n};var Yt=(n,t,e)=>(e=n!=null?pp(Ap(n)):{},Ep(t||!n||!n.__esModule?$c(e,"default",{value:n,enumerable:!0}):e,n));var ji=lt((Yy,Fc)=>{Fc.exports={newInvalidAsn1Error:function(n){var t=new Error;return t.name="InvalidAsn1Error",t.message=n||"",t}}});var Xi=lt((jy,Hc)=>{Hc.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 yo=lt((Xy,Qc)=>{"use strict";var Ji=require("buffer"),Br=Ji.Buffer,mn={},gn;for(gn in Ji)Ji.hasOwnProperty(gn)&&(gn==="SlowBuffer"||gn==="Buffer"||(mn[gn]=Ji[gn]));var Rr=mn.Buffer={};for(gn in Br)Br.hasOwnProperty(gn)&&(gn==="allocUnsafe"||gn==="allocUnsafeSlow"||(Rr[gn]=Br[gn]));mn.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(!mn.kStringMaxLength)try{mn.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch{}mn.constants||(mn.constants={MAX_LENGTH:mn.kMaxLength},mn.kStringMaxLength&&(mn.constants.MAX_STRING_LENGTH=mn.kStringMaxLength));Qc.exports=mn});var Kc=lt((Jy,qc)=>{var _p=require("assert"),Wc=yo().Buffer,li=Xi(),bp=ji(),Pr=bp.newInvalidAsn1Error;function Jt(n){if(!n||!Wc.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 Pr("Indefinite length not supported");if(t>4)throw Pr("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 Pr("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(li.Integer)};Jt.prototype.readBoolean=function(){return this._readTag(li.Boolean)!==0};Jt.prototype.readEnumeration=function(){return this._readTag(li.Enumeration)};Jt.prototype.readString=function(n,t){n||(n=li.OctetString);var e=this.peek();if(e===null)return null;if(e!==n)throw Pr("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?Wc.alloc(0):"";var i=this._buf.slice(this._offset,this._offset+this.length);return this._offset+=this.length,t?i:i.toString("utf8")};Jt.prototype.readOID=function(n){n||(n=li.OID);var t=this.readString(n,!0);if(t===null)return null;for(var e=[],r=0,i=0;i<t.length;i++){var s=t[i]&255;r<<=7,r+=s&127,(s&128)===0&&(e.push(r),r=0)}return r=e.shift(),e.unshift(r%40),e.unshift(r/40>>0),e.join(".")};Jt.prototype._readTag=function(n){_p.ok(n!==void 0);var t=this.peek();if(t===null)return null;if(t!==n)throw Pr("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 Pr("Integer too long: "+this.length);if(this.length>this._size-e)return null;this._offset=e;for(var r=this._buf[this._offset],i=0,s=0;s<this.length;s++)i<<=8,i|=this._buf[this._offset++]&255;return(r&128)===128&&s!==4&&(i-=1<<s*8),i>>0};qc.exports=Jt});var zc=lt((Zy,Vc)=>{var Kn=require("assert"),Zi=yo().Buffer,Vn=Xi(),Sp=ji(),es=Sp.newInvalidAsn1Error,xp={size:1024,growthFactor:8};function wp(n,t){Kn.ok(n),Kn.equal(typeof n,"object"),Kn.ok(t),Kn.equal(typeof t,"object");var e=Object.getOwnPropertyNames(n);return e.forEach(function(r){if(!t[r]){var i=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(t,r,i)}}),t}function jt(n){n=wp(xp,n||{}),this._buf=Zi.alloc(n.size||1024),this._size=this._buf.length,this._offset=0,this._options=n,this._seq=[]}Object.defineProperty(jt.prototype,"buffer",{get:function(){if(this._seq.length)throw es(this._seq.length+" unended sequence(s)");return this._buf.slice(0,this._offset)}});jt.prototype.writeByte=function(n){if(typeof n!="number")throw new TypeError("argument must be a Number");this._ensure(1),this._buf[this._offset++]=n};jt.prototype.writeInt=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");typeof t!="number"&&(t=Vn.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};jt.prototype.writeNull=function(){this.writeByte(Vn.Null),this.writeByte(0)};jt.prototype.writeEnumeration=function(n,t){if(typeof n!="number")throw new TypeError("argument must be a Number");return typeof t!="number"&&(t=Vn.Enumeration),this.writeInt(n,t)};jt.prototype.writeBoolean=function(n,t){if(typeof n!="boolean")throw new TypeError("argument must be a Boolean");typeof t!="number"&&(t=Vn.Boolean),this._ensure(3),this._buf[this._offset++]=t,this._buf[this._offset++]=1,this._buf[this._offset++]=n?255:0};jt.prototype.writeString=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string (was: "+typeof n+")");typeof t!="number"&&(t=Vn.OctetString);var e=Zi.byteLength(n);this.writeByte(t),this.writeLength(e),e&&(this._ensure(e),this._buf.write(n,this._offset),this._offset+=e)};jt.prototype.writeBuffer=function(n,t){if(typeof t!="number")throw new TypeError("tag must be a number");if(!Zi.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};jt.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)})};jt.prototype.writeOID=function(n,t){if(typeof n!="string")throw new TypeError("argument must be a string");if(typeof t!="number"&&(t=Vn.OID),!/^([0-9]+\.){3,}[0-9]+$/.test(n))throw new Error("argument is not a valid OID string");function e(o,a){a<128?o.push(a):a<16384?(o.push(a>>>7|128),o.push(a&127)):a<2097152?(o.push(a>>>14|128),o.push((a>>>7|128)&255),o.push(a&127)):a<268435456?(o.push(a>>>21|128),o.push((a>>>14|128)&255),o.push((a>>>7|128)&255),o.push(a&127)):(o.push((a>>>28|128)&255),o.push((a>>>21|128)&255),o.push((a>>>14|128)&255),o.push((a>>>7|128)&255),o.push(a&127))}var r=n.split("."),i=[];i.push(parseInt(r[0],10)*40+parseInt(r[1],10)),r.slice(2).forEach(function(o){e(i,parseInt(o,10))});var s=this;this._ensure(2+i.length),this.writeByte(t),this.writeLength(i.length),i.forEach(function(o){s.writeByte(o)})};jt.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)")};jt.prototype.startSequence=function(n){typeof n!="number"&&(n=Vn.Sequence|Vn.Constructor),this.writeByte(n),this._seq.push(this._offset),this._ensure(3),this._offset+=3};jt.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")};jt.prototype._shift=function(n,t,e){Kn.ok(n!==void 0),Kn.ok(t!==void 0),Kn.ok(e),this._buf.copy(this._buf,n+e,n,n+t),this._offset+=e};jt.prototype._ensure=function(n){if(Kn.ok(n),this._size-this._offset<n){var t=this._size*this._options.growthFactor;t-this._offset<n&&(t+=n);var e=Zi.alloc(t);this._buf.copy(e,0,0,this._offset),this._buf=e,this._size=t}};Vc.exports=jt});var Gc=lt((eE,rs)=>{var Eo=ji(),_o=Xi(),Ip=Kc(),Cp=zc();rs.exports={Reader:Ip,Writer:Cp};for(ts in _o)_o.hasOwnProperty(ts)&&(rs.exports[ts]=_o[ts]);var ts;for(ns in Eo)Eo.hasOwnProperty(ns)&&(rs.exports[ns]=Eo[ns]);var ns});var ui=lt((tE,Yc)=>{var bo=Gc();Yc.exports={Ber:bo,BerReader:bo.Reader,BerWriter:bo.Writer}});var jc=lt((nE,is)=>{(function(n){"use strict";var t=function(m){var A,g=new Float64Array(16);if(m)for(A=0;A<m.length;A++)g[A]=m[A];return g},e=function(){throw new Error("no PRNG")},r=new Uint8Array(16),i=new Uint8Array(32);i[0]=9;var s=t(),o=t([1]),a=t([56129,1]),c=t([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),l=t([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),u=t([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),f=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(m,A,g,d){m[A]=g>>24&255,m[A+1]=g>>16&255,m[A+2]=g>>8&255,m[A+3]=g&255,m[A+4]=d>>24&255,m[A+5]=d>>16&255,m[A+6]=d>>8&255,m[A+7]=d&255}function y(m,A,g,d,_){var D,W=0;for(D=0;D<_;D++)W|=m[A+D]^g[d+D];return(1&W-1>>>8)-1}function E(m,A,g,d){return y(m,A,g,d,16)}function S(m,A,g,d){return y(m,A,g,d,32)}function x(m,A,g,d){for(var _=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,D=g[0]&255|(g[1]&255)<<8|(g[2]&255)<<16|(g[3]&255)<<24,W=g[4]&255|(g[5]&255)<<8|(g[6]&255)<<16|(g[7]&255)<<24,ee=g[8]&255|(g[9]&255)<<8|(g[10]&255)<<16|(g[11]&255)<<24,le=g[12]&255|(g[13]&255)<<8|(g[14]&255)<<16|(g[15]&255)<<24,Ee=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,ge=A[0]&255|(A[1]&255)<<8|(A[2]&255)<<16|(A[3]&255)<<24,it=A[4]&255|(A[5]&255)<<8|(A[6]&255)<<16|(A[7]&255)<<24,ye=A[8]&255|(A[9]&255)<<8|(A[10]&255)<<16|(A[11]&255)<<24,Me=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,Qe=g[16]&255|(g[17]&255)<<8|(g[18]&255)<<16|(g[19]&255)<<24,He=g[20]&255|(g[21]&255)<<8|(g[22]&255)<<16|(g[23]&255)<<24,De=g[24]&255|(g[25]&255)<<8|(g[26]&255)<<16|(g[27]&255)<<24,$e=g[28]&255|(g[29]&255)<<8|(g[30]&255)<<16|(g[31]&255)<<24,Ue=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,_e=_,xe=D,Ae=W,be=ee,Se=le,me=Ee,K=ge,V=it,se=ye,Z=Me,te=Le,ce=Qe,ve=He,We=De,Ke=$e,qe=Ue,I,ze=0;ze<20;ze+=2)I=_e+ve|0,Se^=I<<7|I>>>25,I=Se+_e|0,se^=I<<9|I>>>23,I=se+Se|0,ve^=I<<13|I>>>19,I=ve+se|0,_e^=I<<18|I>>>14,I=me+xe|0,Z^=I<<7|I>>>25,I=Z+me|0,We^=I<<9|I>>>23,I=We+Z|0,xe^=I<<13|I>>>19,I=xe+We|0,me^=I<<18|I>>>14,I=te+K|0,Ke^=I<<7|I>>>25,I=Ke+te|0,Ae^=I<<9|I>>>23,I=Ae+Ke|0,K^=I<<13|I>>>19,I=K+Ae|0,te^=I<<18|I>>>14,I=qe+ce|0,be^=I<<7|I>>>25,I=be+qe|0,V^=I<<9|I>>>23,I=V+be|0,ce^=I<<13|I>>>19,I=ce+V|0,qe^=I<<18|I>>>14,I=_e+be|0,xe^=I<<7|I>>>25,I=xe+_e|0,Ae^=I<<9|I>>>23,I=Ae+xe|0,be^=I<<13|I>>>19,I=be+Ae|0,_e^=I<<18|I>>>14,I=me+Se|0,K^=I<<7|I>>>25,I=K+me|0,V^=I<<9|I>>>23,I=V+K|0,Se^=I<<13|I>>>19,I=Se+V|0,me^=I<<18|I>>>14,I=te+Z|0,ce^=I<<7|I>>>25,I=ce+te|0,se^=I<<9|I>>>23,I=se+ce|0,Z^=I<<13|I>>>19,I=Z+se|0,te^=I<<18|I>>>14,I=qe+Ke|0,ve^=I<<7|I>>>25,I=ve+qe|0,We^=I<<9|I>>>23,I=We+ve|0,Ke^=I<<13|I>>>19,I=Ke+We|0,qe^=I<<18|I>>>14;_e=_e+_|0,xe=xe+D|0,Ae=Ae+W|0,be=be+ee|0,Se=Se+le|0,me=me+Ee|0,K=K+ge|0,V=V+it|0,se=se+ye|0,Z=Z+Me|0,te=te+Le|0,ce=ce+Qe|0,ve=ve+He|0,We=We+De|0,Ke=Ke+$e|0,qe=qe+Ue|0,m[0]=_e>>>0&255,m[1]=_e>>>8&255,m[2]=_e>>>16&255,m[3]=_e>>>24&255,m[4]=xe>>>0&255,m[5]=xe>>>8&255,m[6]=xe>>>16&255,m[7]=xe>>>24&255,m[8]=Ae>>>0&255,m[9]=Ae>>>8&255,m[10]=Ae>>>16&255,m[11]=Ae>>>24&255,m[12]=be>>>0&255,m[13]=be>>>8&255,m[14]=be>>>16&255,m[15]=be>>>24&255,m[16]=Se>>>0&255,m[17]=Se>>>8&255,m[18]=Se>>>16&255,m[19]=Se>>>24&255,m[20]=me>>>0&255,m[21]=me>>>8&255,m[22]=me>>>16&255,m[23]=me>>>24&255,m[24]=K>>>0&255,m[25]=K>>>8&255,m[26]=K>>>16&255,m[27]=K>>>24&255,m[28]=V>>>0&255,m[29]=V>>>8&255,m[30]=V>>>16&255,m[31]=V>>>24&255,m[32]=se>>>0&255,m[33]=se>>>8&255,m[34]=se>>>16&255,m[35]=se>>>24&255,m[36]=Z>>>0&255,m[37]=Z>>>8&255,m[38]=Z>>>16&255,m[39]=Z>>>24&255,m[40]=te>>>0&255,m[41]=te>>>8&255,m[42]=te>>>16&255,m[43]=te>>>24&255,m[44]=ce>>>0&255,m[45]=ce>>>8&255,m[46]=ce>>>16&255,m[47]=ce>>>24&255,m[48]=ve>>>0&255,m[49]=ve>>>8&255,m[50]=ve>>>16&255,m[51]=ve>>>24&255,m[52]=We>>>0&255,m[53]=We>>>8&255,m[54]=We>>>16&255,m[55]=We>>>24&255,m[56]=Ke>>>0&255,m[57]=Ke>>>8&255,m[58]=Ke>>>16&255,m[59]=Ke>>>24&255,m[60]=qe>>>0&255,m[61]=qe>>>8&255,m[62]=qe>>>16&255,m[63]=qe>>>24&255}function P(m,A,g,d){for(var _=d[0]&255|(d[1]&255)<<8|(d[2]&255)<<16|(d[3]&255)<<24,D=g[0]&255|(g[1]&255)<<8|(g[2]&255)<<16|(g[3]&255)<<24,W=g[4]&255|(g[5]&255)<<8|(g[6]&255)<<16|(g[7]&255)<<24,ee=g[8]&255|(g[9]&255)<<8|(g[10]&255)<<16|(g[11]&255)<<24,le=g[12]&255|(g[13]&255)<<8|(g[14]&255)<<16|(g[15]&255)<<24,Ee=d[4]&255|(d[5]&255)<<8|(d[6]&255)<<16|(d[7]&255)<<24,ge=A[0]&255|(A[1]&255)<<8|(A[2]&255)<<16|(A[3]&255)<<24,it=A[4]&255|(A[5]&255)<<8|(A[6]&255)<<16|(A[7]&255)<<24,ye=A[8]&255|(A[9]&255)<<8|(A[10]&255)<<16|(A[11]&255)<<24,Me=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,Qe=g[16]&255|(g[17]&255)<<8|(g[18]&255)<<16|(g[19]&255)<<24,He=g[20]&255|(g[21]&255)<<8|(g[22]&255)<<16|(g[23]&255)<<24,De=g[24]&255|(g[25]&255)<<8|(g[26]&255)<<16|(g[27]&255)<<24,$e=g[28]&255|(g[29]&255)<<8|(g[30]&255)<<16|(g[31]&255)<<24,Ue=d[12]&255|(d[13]&255)<<8|(d[14]&255)<<16|(d[15]&255)<<24,_e=_,xe=D,Ae=W,be=ee,Se=le,me=Ee,K=ge,V=it,se=ye,Z=Me,te=Le,ce=Qe,ve=He,We=De,Ke=$e,qe=Ue,I,ze=0;ze<20;ze+=2)I=_e+ve|0,Se^=I<<7|I>>>25,I=Se+_e|0,se^=I<<9|I>>>23,I=se+Se|0,ve^=I<<13|I>>>19,I=ve+se|0,_e^=I<<18|I>>>14,I=me+xe|0,Z^=I<<7|I>>>25,I=Z+me|0,We^=I<<9|I>>>23,I=We+Z|0,xe^=I<<13|I>>>19,I=xe+We|0,me^=I<<18|I>>>14,I=te+K|0,Ke^=I<<7|I>>>25,I=Ke+te|0,Ae^=I<<9|I>>>23,I=Ae+Ke|0,K^=I<<13|I>>>19,I=K+Ae|0,te^=I<<18|I>>>14,I=qe+ce|0,be^=I<<7|I>>>25,I=be+qe|0,V^=I<<9|I>>>23,I=V+be|0,ce^=I<<13|I>>>19,I=ce+V|0,qe^=I<<18|I>>>14,I=_e+be|0,xe^=I<<7|I>>>25,I=xe+_e|0,Ae^=I<<9|I>>>23,I=Ae+xe|0,be^=I<<13|I>>>19,I=be+Ae|0,_e^=I<<18|I>>>14,I=me+Se|0,K^=I<<7|I>>>25,I=K+me|0,V^=I<<9|I>>>23,I=V+K|0,Se^=I<<13|I>>>19,I=Se+V|0,me^=I<<18|I>>>14,I=te+Z|0,ce^=I<<7|I>>>25,I=ce+te|0,se^=I<<9|I>>>23,I=se+ce|0,Z^=I<<13|I>>>19,I=Z+se|0,te^=I<<18|I>>>14,I=qe+Ke|0,ve^=I<<7|I>>>25,I=ve+qe|0,We^=I<<9|I>>>23,I=We+ve|0,Ke^=I<<13|I>>>19,I=Ke+We|0,qe^=I<<18|I>>>14;m[0]=_e>>>0&255,m[1]=_e>>>8&255,m[2]=_e>>>16&255,m[3]=_e>>>24&255,m[4]=me>>>0&255,m[5]=me>>>8&255,m[6]=me>>>16&255,m[7]=me>>>24&255,m[8]=te>>>0&255,m[9]=te>>>8&255,m[10]=te>>>16&255,m[11]=te>>>24&255,m[12]=qe>>>0&255,m[13]=qe>>>8&255,m[14]=qe>>>16&255,m[15]=qe>>>24&255,m[16]=K>>>0&255,m[17]=K>>>8&255,m[18]=K>>>16&255,m[19]=K>>>24&255,m[20]=V>>>0&255,m[21]=V>>>8&255,m[22]=V>>>16&255,m[23]=V>>>24&255,m[24]=se>>>0&255,m[25]=se>>>8&255,m[26]=se>>>16&255,m[27]=se>>>24&255,m[28]=Z>>>0&255,m[29]=Z>>>8&255,m[30]=Z>>>16&255,m[31]=Z>>>24&255}function q(m,A,g,d){x(m,A,g,d)}function C(m,A,g,d){P(m,A,g,d)}var $=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function F(m,A,g,d,_,D,W){var ee=new Uint8Array(16),le=new Uint8Array(64),Ee,ge;for(ge=0;ge<16;ge++)ee[ge]=0;for(ge=0;ge<8;ge++)ee[ge]=D[ge];for(;_>=64;){for(q(le,ee,W,$),ge=0;ge<64;ge++)m[A+ge]=g[d+ge]^le[ge];for(Ee=1,ge=8;ge<16;ge++)Ee=Ee+(ee[ge]&255)|0,ee[ge]=Ee&255,Ee>>>=8;_-=64,A+=64,d+=64}if(_>0)for(q(le,ee,W,$),ge=0;ge<_;ge++)m[A+ge]=g[d+ge]^le[ge];return 0}function v(m,A,g,d,_){var D=new Uint8Array(16),W=new Uint8Array(64),ee,le;for(le=0;le<16;le++)D[le]=0;for(le=0;le<8;le++)D[le]=d[le];for(;g>=64;){for(q(W,D,_,$),le=0;le<64;le++)m[A+le]=W[le];for(ee=1,le=8;le<16;le++)ee=ee+(D[le]&255)|0,D[le]=ee&255,ee>>>=8;g-=64,A+=64}if(g>0)for(q(W,D,_,$),le=0;le<g;le++)m[A+le]=W[le];return 0}function b(m,A,g,d,_){var D=new Uint8Array(32);C(D,d,_,$);for(var W=new Uint8Array(8),ee=0;ee<8;ee++)W[ee]=d[ee+16];return v(m,A,g,W,D)}function w(m,A,g,d,_,D,W){var ee=new Uint8Array(32);C(ee,D,W,$);for(var le=new Uint8Array(8),Ee=0;Ee<8;Ee++)le[Ee]=D[Ee+16];return F(m,A,g,d,_,le,ee)}var k=function(m){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,g,d,_,D,W,ee,le;A=m[0]&255|(m[1]&255)<<8,this.r[0]=A&8191,g=m[2]&255|(m[3]&255)<<8,this.r[1]=(A>>>13|g<<3)&8191,d=m[4]&255|(m[5]&255)<<8,this.r[2]=(g>>>10|d<<6)&7939,_=m[6]&255|(m[7]&255)<<8,this.r[3]=(d>>>7|_<<9)&8191,D=m[8]&255|(m[9]&255)<<8,this.r[4]=(_>>>4|D<<12)&255,this.r[5]=D>>>1&8190,W=m[10]&255|(m[11]&255)<<8,this.r[6]=(D>>>14|W<<2)&8191,ee=m[12]&255|(m[13]&255)<<8,this.r[7]=(W>>>11|ee<<5)&8065,le=m[14]&255|(m[15]&255)<<8,this.r[8]=(ee>>>8|le<<8)&8191,this.r[9]=le>>>5&127,this.pad[0]=m[16]&255|(m[17]&255)<<8,this.pad[1]=m[18]&255|(m[19]&255)<<8,this.pad[2]=m[20]&255|(m[21]&255)<<8,this.pad[3]=m[22]&255|(m[23]&255)<<8,this.pad[4]=m[24]&255|(m[25]&255)<<8,this.pad[5]=m[26]&255|(m[27]&255)<<8,this.pad[6]=m[28]&255|(m[29]&255)<<8,this.pad[7]=m[30]&255|(m[31]&255)<<8};k.prototype.blocks=function(m,A,g){for(var d=this.fin?0:2048,_,D,W,ee,le,Ee,ge,it,ye,Me,Le,Qe,He,De,$e,Ue,_e,xe,Ae,be=this.h[0],Se=this.h[1],me=this.h[2],K=this.h[3],V=this.h[4],se=this.h[5],Z=this.h[6],te=this.h[7],ce=this.h[8],ve=this.h[9],We=this.r[0],Ke=this.r[1],qe=this.r[2],I=this.r[3],ze=this.r[4],st=this.r[5],ot=this.r[6],Ve=this.r[7],et=this.r[8],tt=this.r[9];g>=16;)_=m[A+0]&255|(m[A+1]&255)<<8,be+=_&8191,D=m[A+2]&255|(m[A+3]&255)<<8,Se+=(_>>>13|D<<3)&8191,W=m[A+4]&255|(m[A+5]&255)<<8,me+=(D>>>10|W<<6)&8191,ee=m[A+6]&255|(m[A+7]&255)<<8,K+=(W>>>7|ee<<9)&8191,le=m[A+8]&255|(m[A+9]&255)<<8,V+=(ee>>>4|le<<12)&8191,se+=le>>>1&8191,Ee=m[A+10]&255|(m[A+11]&255)<<8,Z+=(le>>>14|Ee<<2)&8191,ge=m[A+12]&255|(m[A+13]&255)<<8,te+=(Ee>>>11|ge<<5)&8191,it=m[A+14]&255|(m[A+15]&255)<<8,ce+=(ge>>>8|it<<8)&8191,ve+=it>>>5|d,ye=0,Me=ye,Me+=be*We,Me+=Se*(5*tt),Me+=me*(5*et),Me+=K*(5*Ve),Me+=V*(5*ot),ye=Me>>>13,Me&=8191,Me+=se*(5*st),Me+=Z*(5*ze),Me+=te*(5*I),Me+=ce*(5*qe),Me+=ve*(5*Ke),ye+=Me>>>13,Me&=8191,Le=ye,Le+=be*Ke,Le+=Se*We,Le+=me*(5*tt),Le+=K*(5*et),Le+=V*(5*Ve),ye=Le>>>13,Le&=8191,Le+=se*(5*ot),Le+=Z*(5*st),Le+=te*(5*ze),Le+=ce*(5*I),Le+=ve*(5*qe),ye+=Le>>>13,Le&=8191,Qe=ye,Qe+=be*qe,Qe+=Se*Ke,Qe+=me*We,Qe+=K*(5*tt),Qe+=V*(5*et),ye=Qe>>>13,Qe&=8191,Qe+=se*(5*Ve),Qe+=Z*(5*ot),Qe+=te*(5*st),Qe+=ce*(5*ze),Qe+=ve*(5*I),ye+=Qe>>>13,Qe&=8191,He=ye,He+=be*I,He+=Se*qe,He+=me*Ke,He+=K*We,He+=V*(5*tt),ye=He>>>13,He&=8191,He+=se*(5*et),He+=Z*(5*Ve),He+=te*(5*ot),He+=ce*(5*st),He+=ve*(5*ze),ye+=He>>>13,He&=8191,De=ye,De+=be*ze,De+=Se*I,De+=me*qe,De+=K*Ke,De+=V*We,ye=De>>>13,De&=8191,De+=se*(5*tt),De+=Z*(5*et),De+=te*(5*Ve),De+=ce*(5*ot),De+=ve*(5*st),ye+=De>>>13,De&=8191,$e=ye,$e+=be*st,$e+=Se*ze,$e+=me*I,$e+=K*qe,$e+=V*Ke,ye=$e>>>13,$e&=8191,$e+=se*We,$e+=Z*(5*tt),$e+=te*(5*et),$e+=ce*(5*Ve),$e+=ve*(5*ot),ye+=$e>>>13,$e&=8191,Ue=ye,Ue+=be*ot,Ue+=Se*st,Ue+=me*ze,Ue+=K*I,Ue+=V*qe,ye=Ue>>>13,Ue&=8191,Ue+=se*Ke,Ue+=Z*We,Ue+=te*(5*tt),Ue+=ce*(5*et),Ue+=ve*(5*Ve),ye+=Ue>>>13,Ue&=8191,_e=ye,_e+=be*Ve,_e+=Se*ot,_e+=me*st,_e+=K*ze,_e+=V*I,ye=_e>>>13,_e&=8191,_e+=se*qe,_e+=Z*Ke,_e+=te*We,_e+=ce*(5*tt),_e+=ve*(5*et),ye+=_e>>>13,_e&=8191,xe=ye,xe+=be*et,xe+=Se*Ve,xe+=me*ot,xe+=K*st,xe+=V*ze,ye=xe>>>13,xe&=8191,xe+=se*I,xe+=Z*qe,xe+=te*Ke,xe+=ce*We,xe+=ve*(5*tt),ye+=xe>>>13,xe&=8191,Ae=ye,Ae+=be*tt,Ae+=Se*et,Ae+=me*Ve,Ae+=K*ot,Ae+=V*st,ye=Ae>>>13,Ae&=8191,Ae+=se*ze,Ae+=Z*I,Ae+=te*qe,Ae+=ce*Ke,Ae+=ve*We,ye+=Ae>>>13,Ae&=8191,ye=(ye<<2)+ye|0,ye=ye+Me|0,Me=ye&8191,ye=ye>>>13,Le+=ye,be=Me,Se=Le,me=Qe,K=He,V=De,se=$e,Z=Ue,te=_e,ce=xe,ve=Ae,A+=16,g-=16;this.h[0]=be,this.h[1]=Se,this.h[2]=me,this.h[3]=K,this.h[4]=V,this.h[5]=se,this.h[6]=Z,this.h[7]=te,this.h[8]=ce,this.h[9]=ve},k.prototype.finish=function(m,A){var g=new Uint16Array(10),d,_,D,W;if(this.leftover){for(W=this.leftover,this.buffer[W++]=1;W<16;W++)this.buffer[W]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(d=this.h[1]>>>13,this.h[1]&=8191,W=2;W<10;W++)this.h[W]+=d,d=this.h[W]>>>13,this.h[W]&=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,g[0]=this.h[0]+5,d=g[0]>>>13,g[0]&=8191,W=1;W<10;W++)g[W]=this.h[W]+d,d=g[W]>>>13,g[W]&=8191;for(g[9]-=8192,_=(d^1)-1,W=0;W<10;W++)g[W]&=_;for(_=~_,W=0;W<10;W++)this.h[W]=this.h[W]&_|g[W];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,D=this.h[0]+this.pad[0],this.h[0]=D&65535,W=1;W<8;W++)D=(this.h[W]+this.pad[W]|0)+(D>>>16)|0,this.h[W]=D&65535;m[A+0]=this.h[0]>>>0&255,m[A+1]=this.h[0]>>>8&255,m[A+2]=this.h[1]>>>0&255,m[A+3]=this.h[1]>>>8&255,m[A+4]=this.h[2]>>>0&255,m[A+5]=this.h[2]>>>8&255,m[A+6]=this.h[3]>>>0&255,m[A+7]=this.h[3]>>>8&255,m[A+8]=this.h[4]>>>0&255,m[A+9]=this.h[4]>>>8&255,m[A+10]=this.h[5]>>>0&255,m[A+11]=this.h[5]>>>8&255,m[A+12]=this.h[6]>>>0&255,m[A+13]=this.h[6]>>>8&255,m[A+14]=this.h[7]>>>0&255,m[A+15]=this.h[7]>>>8&255},k.prototype.update=function(m,A,g){var d,_;if(this.leftover){for(_=16-this.leftover,_>g&&(_=g),d=0;d<_;d++)this.buffer[this.leftover+d]=m[A+d];if(g-=_,A+=_,this.leftover+=_,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(g>=16&&(_=g-g%16,this.blocks(m,A,_),A+=_,g-=_),g){for(d=0;d<g;d++)this.buffer[this.leftover+d]=m[A+d];this.leftover+=g}};function N(m,A,g,d,_,D){var W=new k(D);return W.update(g,d,_),W.finish(m,A),0}function R(m,A,g,d,_,D){var W=new Uint8Array(16);return N(W,0,g,d,_,D),E(m,A,W,0)}function ie(m,A,g,d,_){var D;if(g<32)return-1;for(w(m,0,A,0,g,d,_),N(m,16,m,32,g-32,m),D=0;D<16;D++)m[D]=0;return 0}function j(m,A,g,d,_){var D,W=new Uint8Array(32);if(g<32||(b(W,0,32,d,_),R(A,16,A,32,g-32,W)!==0))return-1;for(w(m,0,A,0,g,d,_),D=0;D<32;D++)m[D]=0;return 0}function X(m,A){var g;for(g=0;g<16;g++)m[g]=A[g]|0}function re(m){var A,g,d=1;for(A=0;A<16;A++)g=m[A]+d+65535,d=Math.floor(g/65536),m[A]=g-d*65536;m[0]+=d-1+37*(d-1)}function fe(m,A,g){for(var d,_=~(g-1),D=0;D<16;D++)d=_&(m[D]^A[D]),m[D]^=d,A[D]^=d}function H(m,A){var g,d,_,D=t(),W=t();for(g=0;g<16;g++)W[g]=A[g];for(re(W),re(W),re(W),d=0;d<2;d++){for(D[0]=W[0]-65517,g=1;g<15;g++)D[g]=W[g]-65535-(D[g-1]>>16&1),D[g-1]&=65535;D[15]=W[15]-32767-(D[14]>>16&1),_=D[15]>>16&1,D[14]&=65535,fe(W,D,1-_)}for(g=0;g<16;g++)m[2*g]=W[g]&255,m[2*g+1]=W[g]>>8}function B(m,A){var g=new Uint8Array(32),d=new Uint8Array(32);return H(g,m),H(d,A),S(g,0,d,0)}function L(m){var A=new Uint8Array(32);return H(A,m),A[0]&1}function z(m,A){var g;for(g=0;g<16;g++)m[g]=A[2*g]+(A[2*g+1]<<8);m[15]&=32767}function ne(m,A,g){for(var d=0;d<16;d++)m[d]=A[d]+g[d]}function de(m,A,g){for(var d=0;d<16;d++)m[d]=A[d]-g[d]}function oe(m,A,g){var d,_,D=0,W=0,ee=0,le=0,Ee=0,ge=0,it=0,ye=0,Me=0,Le=0,Qe=0,He=0,De=0,$e=0,Ue=0,_e=0,xe=0,Ae=0,be=0,Se=0,me=0,K=0,V=0,se=0,Z=0,te=0,ce=0,ve=0,We=0,Ke=0,qe=0,I=g[0],ze=g[1],st=g[2],ot=g[3],Ve=g[4],et=g[5],tt=g[6],Rt=g[7],ht=g[8],vt=g[9],Nt=g[10],Bt=g[11],$t=g[12],Vt=g[13],zt=g[14],Gt=g[15];d=A[0],D+=d*I,W+=d*ze,ee+=d*st,le+=d*ot,Ee+=d*Ve,ge+=d*et,it+=d*tt,ye+=d*Rt,Me+=d*ht,Le+=d*vt,Qe+=d*Nt,He+=d*Bt,De+=d*$t,$e+=d*Vt,Ue+=d*zt,_e+=d*Gt,d=A[1],W+=d*I,ee+=d*ze,le+=d*st,Ee+=d*ot,ge+=d*Ve,it+=d*et,ye+=d*tt,Me+=d*Rt,Le+=d*ht,Qe+=d*vt,He+=d*Nt,De+=d*Bt,$e+=d*$t,Ue+=d*Vt,_e+=d*zt,xe+=d*Gt,d=A[2],ee+=d*I,le+=d*ze,Ee+=d*st,ge+=d*ot,it+=d*Ve,ye+=d*et,Me+=d*tt,Le+=d*Rt,Qe+=d*ht,He+=d*vt,De+=d*Nt,$e+=d*Bt,Ue+=d*$t,_e+=d*Vt,xe+=d*zt,Ae+=d*Gt,d=A[3],le+=d*I,Ee+=d*ze,ge+=d*st,it+=d*ot,ye+=d*Ve,Me+=d*et,Le+=d*tt,Qe+=d*Rt,He+=d*ht,De+=d*vt,$e+=d*Nt,Ue+=d*Bt,_e+=d*$t,xe+=d*Vt,Ae+=d*zt,be+=d*Gt,d=A[4],Ee+=d*I,ge+=d*ze,it+=d*st,ye+=d*ot,Me+=d*Ve,Le+=d*et,Qe+=d*tt,He+=d*Rt,De+=d*ht,$e+=d*vt,Ue+=d*Nt,_e+=d*Bt,xe+=d*$t,Ae+=d*Vt,be+=d*zt,Se+=d*Gt,d=A[5],ge+=d*I,it+=d*ze,ye+=d*st,Me+=d*ot,Le+=d*Ve,Qe+=d*et,He+=d*tt,De+=d*Rt,$e+=d*ht,Ue+=d*vt,_e+=d*Nt,xe+=d*Bt,Ae+=d*$t,be+=d*Vt,Se+=d*zt,me+=d*Gt,d=A[6],it+=d*I,ye+=d*ze,Me+=d*st,Le+=d*ot,Qe+=d*Ve,He+=d*et,De+=d*tt,$e+=d*Rt,Ue+=d*ht,_e+=d*vt,xe+=d*Nt,Ae+=d*Bt,be+=d*$t,Se+=d*Vt,me+=d*zt,K+=d*Gt,d=A[7],ye+=d*I,Me+=d*ze,Le+=d*st,Qe+=d*ot,He+=d*Ve,De+=d*et,$e+=d*tt,Ue+=d*Rt,_e+=d*ht,xe+=d*vt,Ae+=d*Nt,be+=d*Bt,Se+=d*$t,me+=d*Vt,K+=d*zt,V+=d*Gt,d=A[8],Me+=d*I,Le+=d*ze,Qe+=d*st,He+=d*ot,De+=d*Ve,$e+=d*et,Ue+=d*tt,_e+=d*Rt,xe+=d*ht,Ae+=d*vt,be+=d*Nt,Se+=d*Bt,me+=d*$t,K+=d*Vt,V+=d*zt,se+=d*Gt,d=A[9],Le+=d*I,Qe+=d*ze,He+=d*st,De+=d*ot,$e+=d*Ve,Ue+=d*et,_e+=d*tt,xe+=d*Rt,Ae+=d*ht,be+=d*vt,Se+=d*Nt,me+=d*Bt,K+=d*$t,V+=d*Vt,se+=d*zt,Z+=d*Gt,d=A[10],Qe+=d*I,He+=d*ze,De+=d*st,$e+=d*ot,Ue+=d*Ve,_e+=d*et,xe+=d*tt,Ae+=d*Rt,be+=d*ht,Se+=d*vt,me+=d*Nt,K+=d*Bt,V+=d*$t,se+=d*Vt,Z+=d*zt,te+=d*Gt,d=A[11],He+=d*I,De+=d*ze,$e+=d*st,Ue+=d*ot,_e+=d*Ve,xe+=d*et,Ae+=d*tt,be+=d*Rt,Se+=d*ht,me+=d*vt,K+=d*Nt,V+=d*Bt,se+=d*$t,Z+=d*Vt,te+=d*zt,ce+=d*Gt,d=A[12],De+=d*I,$e+=d*ze,Ue+=d*st,_e+=d*ot,xe+=d*Ve,Ae+=d*et,be+=d*tt,Se+=d*Rt,me+=d*ht,K+=d*vt,V+=d*Nt,se+=d*Bt,Z+=d*$t,te+=d*Vt,ce+=d*zt,ve+=d*Gt,d=A[13],$e+=d*I,Ue+=d*ze,_e+=d*st,xe+=d*ot,Ae+=d*Ve,be+=d*et,Se+=d*tt,me+=d*Rt,K+=d*ht,V+=d*vt,se+=d*Nt,Z+=d*Bt,te+=d*$t,ce+=d*Vt,ve+=d*zt,We+=d*Gt,d=A[14],Ue+=d*I,_e+=d*ze,xe+=d*st,Ae+=d*ot,be+=d*Ve,Se+=d*et,me+=d*tt,K+=d*Rt,V+=d*ht,se+=d*vt,Z+=d*Nt,te+=d*Bt,ce+=d*$t,ve+=d*Vt,We+=d*zt,Ke+=d*Gt,d=A[15],_e+=d*I,xe+=d*ze,Ae+=d*st,be+=d*ot,Se+=d*Ve,me+=d*et,K+=d*tt,V+=d*Rt,se+=d*ht,Z+=d*vt,te+=d*Nt,ce+=d*Bt,ve+=d*$t,We+=d*Vt,Ke+=d*zt,qe+=d*Gt,D+=38*xe,W+=38*Ae,ee+=38*be,le+=38*Se,Ee+=38*me,ge+=38*K,it+=38*V,ye+=38*se,Me+=38*Z,Le+=38*te,Qe+=38*ce,He+=38*ve,De+=38*We,$e+=38*Ke,Ue+=38*qe,_=1,d=D+_+65535,_=Math.floor(d/65536),D=d-_*65536,d=W+_+65535,_=Math.floor(d/65536),W=d-_*65536,d=ee+_+65535,_=Math.floor(d/65536),ee=d-_*65536,d=le+_+65535,_=Math.floor(d/65536),le=d-_*65536,d=Ee+_+65535,_=Math.floor(d/65536),Ee=d-_*65536,d=ge+_+65535,_=Math.floor(d/65536),ge=d-_*65536,d=it+_+65535,_=Math.floor(d/65536),it=d-_*65536,d=ye+_+65535,_=Math.floor(d/65536),ye=d-_*65536,d=Me+_+65535,_=Math.floor(d/65536),Me=d-_*65536,d=Le+_+65535,_=Math.floor(d/65536),Le=d-_*65536,d=Qe+_+65535,_=Math.floor(d/65536),Qe=d-_*65536,d=He+_+65535,_=Math.floor(d/65536),He=d-_*65536,d=De+_+65535,_=Math.floor(d/65536),De=d-_*65536,d=$e+_+65535,_=Math.floor(d/65536),$e=d-_*65536,d=Ue+_+65535,_=Math.floor(d/65536),Ue=d-_*65536,d=_e+_+65535,_=Math.floor(d/65536),_e=d-_*65536,D+=_-1+37*(_-1),_=1,d=D+_+65535,_=Math.floor(d/65536),D=d-_*65536,d=W+_+65535,_=Math.floor(d/65536),W=d-_*65536,d=ee+_+65535,_=Math.floor(d/65536),ee=d-_*65536,d=le+_+65535,_=Math.floor(d/65536),le=d-_*65536,d=Ee+_+65535,_=Math.floor(d/65536),Ee=d-_*65536,d=ge+_+65535,_=Math.floor(d/65536),ge=d-_*65536,d=it+_+65535,_=Math.floor(d/65536),it=d-_*65536,d=ye+_+65535,_=Math.floor(d/65536),ye=d-_*65536,d=Me+_+65535,_=Math.floor(d/65536),Me=d-_*65536,d=Le+_+65535,_=Math.floor(d/65536),Le=d-_*65536,d=Qe+_+65535,_=Math.floor(d/65536),Qe=d-_*65536,d=He+_+65535,_=Math.floor(d/65536),He=d-_*65536,d=De+_+65535,_=Math.floor(d/65536),De=d-_*65536,d=$e+_+65535,_=Math.floor(d/65536),$e=d-_*65536,d=Ue+_+65535,_=Math.floor(d/65536),Ue=d-_*65536,d=_e+_+65535,_=Math.floor(d/65536),_e=d-_*65536,D+=_-1+37*(_-1),m[0]=D,m[1]=W,m[2]=ee,m[3]=le,m[4]=Ee,m[5]=ge,m[6]=it,m[7]=ye,m[8]=Me,m[9]=Le,m[10]=Qe,m[11]=He,m[12]=De,m[13]=$e,m[14]=Ue,m[15]=_e}function Xe(m,A){oe(m,A,A)}function dt(m,A){var g=t(),d;for(d=0;d<16;d++)g[d]=A[d];for(d=253;d>=0;d--)Xe(g,g),d!==2&&d!==4&&oe(g,g,A);for(d=0;d<16;d++)m[d]=g[d]}function cn(m,A){var g=t(),d;for(d=0;d<16;d++)g[d]=A[d];for(d=250;d>=0;d--)Xe(g,g),d!==1&&oe(g,g,A);for(d=0;d<16;d++)m[d]=g[d]}function Sr(m,A,g){var d=new Uint8Array(32),_=new Float64Array(80),D,W,ee=t(),le=t(),Ee=t(),ge=t(),it=t(),ye=t();for(W=0;W<31;W++)d[W]=A[W];for(d[31]=A[31]&127|64,d[0]&=248,z(_,g),W=0;W<16;W++)le[W]=_[W],ge[W]=ee[W]=Ee[W]=0;for(ee[0]=ge[0]=1,W=254;W>=0;--W)D=d[W>>>3]>>>(W&7)&1,fe(ee,le,D),fe(Ee,ge,D),ne(it,ee,Ee),de(ee,ee,Ee),ne(Ee,le,ge),de(le,le,ge),Xe(ge,it),Xe(ye,ee),oe(ee,Ee,ee),oe(Ee,le,it),ne(it,ee,Ee),de(ee,ee,Ee),Xe(le,ee),de(Ee,ge,ye),oe(ee,Ee,a),ne(ee,ee,ge),oe(Ee,Ee,ee),oe(ee,ge,ye),oe(ge,le,_),Xe(le,it),fe(ee,le,D),fe(Ee,ge,D);for(W=0;W<16;W++)_[W+16]=ee[W],_[W+32]=Ee[W],_[W+48]=le[W],_[W+64]=ge[W];var Me=_.subarray(32),Le=_.subarray(16);return dt(Me,Me),oe(Le,Le,Me),H(m,Le),0}function xr(m,A){return Sr(m,A,i)}function On(m,A){return e(A,32),xr(m,A)}function wr(m,A,g){var d=new Uint8Array(32);return Sr(d,g,A),C(m,r,d,$)}var ii=ie,Gi=j;function si(m,A,g,d,_,D){var W=new Uint8Array(32);return wr(W,_,D),ii(m,A,g,d,W)}function Ir(m,A,g,d,_,D){var W=new Uint8Array(32);return wr(W,_,D),Gi(m,A,g,d,W)}var Cr=[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(m,A,g,d){for(var _=new Int32Array(16),D=new Int32Array(16),W,ee,le,Ee,ge,it,ye,Me,Le,Qe,He,De,$e,Ue,_e,xe,Ae,be,Se,me,K,V,se,Z,te,ce,ve=m[0],We=m[1],Ke=m[2],qe=m[3],I=m[4],ze=m[5],st=m[6],ot=m[7],Ve=A[0],et=A[1],tt=A[2],Rt=A[3],ht=A[4],vt=A[5],Nt=A[6],Bt=A[7],$t=0;d>=128;){for(Se=0;Se<16;Se++)me=8*Se+$t,_[Se]=g[me+0]<<24|g[me+1]<<16|g[me+2]<<8|g[me+3],D[Se]=g[me+4]<<24|g[me+5]<<16|g[me+6]<<8|g[me+7];for(Se=0;Se<80;Se++)if(W=ve,ee=We,le=Ke,Ee=qe,ge=I,it=ze,ye=st,Me=ot,Le=Ve,Qe=et,He=tt,De=Rt,$e=ht,Ue=vt,_e=Nt,xe=Bt,K=ot,V=Bt,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=(I>>>14|ht<<18)^(I>>>18|ht<<14)^(ht>>>9|I<<23),V=(ht>>>14|I<<18)^(ht>>>18|I<<14)^(I>>>9|ht<<23),se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,K=I&ze^~I&st,V=ht&vt^~ht&Nt,se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,K=Cr[Se*2],V=Cr[Se*2+1],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,K=_[Se%16],V=D[Se%16],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,Ae=te&65535|ce<<16,be=se&65535|Z<<16,K=Ae,V=be,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=(ve>>>28|Ve<<4)^(Ve>>>2|ve<<30)^(Ve>>>7|ve<<25),V=(Ve>>>28|ve<<4)^(ve>>>2|Ve<<30)^(ve>>>7|Ve<<25),se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,K=ve&We^ve&Ke^We&Ke,V=Ve&et^Ve&tt^et&tt,se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,Me=te&65535|ce<<16,xe=se&65535|Z<<16,K=Ee,V=De,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=Ae,V=be,se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,Ee=te&65535|ce<<16,De=se&65535|Z<<16,We=W,Ke=ee,qe=le,I=Ee,ze=ge,st=it,ot=ye,ve=Me,et=Le,tt=Qe,Rt=He,ht=De,vt=$e,Nt=Ue,Bt=_e,Ve=xe,Se%16===15)for(me=0;me<16;me++)K=_[me],V=D[me],se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=_[(me+9)%16],V=D[(me+9)%16],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Ae=_[(me+1)%16],be=D[(me+1)%16],K=(Ae>>>1|be<<31)^(Ae>>>8|be<<24)^Ae>>>7,V=(be>>>1|Ae<<31)^(be>>>8|Ae<<24)^(be>>>7|Ae<<25),se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Ae=_[(me+14)%16],be=D[(me+14)%16],K=(Ae>>>19|be<<13)^(be>>>29|Ae<<3)^Ae>>>6,V=(be>>>19|Ae<<13)^(Ae>>>29|be<<3)^(be>>>6|Ae<<26),se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,_[me]=te&65535|ce<<16,D[me]=se&65535|Z<<16;K=ve,V=Ve,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[0],V=A[0],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[0]=ve=te&65535|ce<<16,A[0]=Ve=se&65535|Z<<16,K=We,V=et,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[1],V=A[1],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[1]=We=te&65535|ce<<16,A[1]=et=se&65535|Z<<16,K=Ke,V=tt,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[2],V=A[2],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[2]=Ke=te&65535|ce<<16,A[2]=tt=se&65535|Z<<16,K=qe,V=Rt,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[3],V=A[3],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[3]=qe=te&65535|ce<<16,A[3]=Rt=se&65535|Z<<16,K=I,V=ht,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[4],V=A[4],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[4]=I=te&65535|ce<<16,A[4]=ht=se&65535|Z<<16,K=ze,V=vt,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[5],V=A[5],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[5]=ze=te&65535|ce<<16,A[5]=vt=se&65535|Z<<16,K=st,V=Nt,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[6],V=A[6],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[6]=st=te&65535|ce<<16,A[6]=Nt=se&65535|Z<<16,K=ot,V=Bt,se=V&65535,Z=V>>>16,te=K&65535,ce=K>>>16,K=m[7],V=A[7],se+=V&65535,Z+=V>>>16,te+=K&65535,ce+=K>>>16,Z+=se>>>16,te+=Z>>>16,ce+=te>>>16,m[7]=ot=te&65535|ce<<16,A[7]=Bt=se&65535|Z<<16,$t+=128,d-=128}return d}function pe(m,A,g){var d=new Int32Array(8),_=new Int32Array(8),D=new Uint8Array(256),W,ee=g;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,_,A,g),g%=128,W=0;W<g;W++)D[W]=A[ee-g+W];for(D[g]=128,g=256-128*(g<112?1:0),D[g-9]=0,p(D,g-8,ee/536870912|0,ee<<3),J(d,_,D,g),W=0;W<8;W++)p(m,8*W,d[W],_[W]);return 0}function we(m,A){var g=t(),d=t(),_=t(),D=t(),W=t(),ee=t(),le=t(),Ee=t(),ge=t();de(g,m[1],m[0]),de(ge,A[1],A[0]),oe(g,g,ge),ne(d,m[0],m[1]),ne(ge,A[0],A[1]),oe(d,d,ge),oe(_,m[3],A[3]),oe(_,_,l),oe(D,m[2],A[2]),ne(D,D,D),de(W,d,g),de(ee,D,_),ne(le,D,_),ne(Ee,d,g),oe(m[0],W,ee),oe(m[1],Ee,le),oe(m[2],le,ee),oe(m[3],W,Ee)}function Oe(m,A,g){var d;for(d=0;d<4;d++)fe(m[d],A[d],g)}function Je(m,A){var g=t(),d=t(),_=t();dt(_,A[2]),oe(g,A[0],_),oe(d,A[1],_),H(m,d),m[31]^=L(g)<<7}function Lt(m,A,g){var d,_;for(X(m[0],s),X(m[1],o),X(m[2],o),X(m[3],s),_=255;_>=0;--_)d=g[_/8|0]>>(_&7)&1,Oe(m,A,d),we(A,m),we(m,m),Oe(m,A,d)}function Cn(m,A){var g=[t(),t(),t(),t()];X(g[0],u),X(g[1],f),X(g[2],o),oe(g[3],u,f),Lt(m,g,A)}function ln(m,A,g){var d=new Uint8Array(64),_=[t(),t(),t(),t()],D;for(g||e(A,32),pe(d,A,32),d[0]&=248,d[31]&=127,d[31]|=64,Cn(_,d),Je(m,_),D=0;D<32;D++)A[D+32]=m[D];return 0}var kr=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 ct(m,A){var g,d,_,D;for(d=63;d>=32;--d){for(g=0,_=d-32,D=d-12;_<D;++_)A[_]+=g-16*A[d]*kr[_-(d-32)],g=A[_]+128>>8,A[_]-=g*256;A[_]+=g,A[d]=0}for(g=0,_=0;_<32;_++)A[_]+=g-(A[31]>>4)*kr[_],g=A[_]>>8,A[_]&=255;for(_=0;_<32;_++)A[_]-=g*kr[_];for(d=0;d<32;d++)A[d+1]+=A[d]>>8,m[d]=A[d]&255}function Ft(m){var A=new Float64Array(64),g;for(g=0;g<64;g++)A[g]=m[g];for(g=0;g<64;g++)m[g]=0;ct(m,A)}function Ut(m,A,g,d){var _=new Uint8Array(64),D=new Uint8Array(64),W=new Uint8Array(64),ee,le,Ee=new Float64Array(64),ge=[t(),t(),t(),t()];pe(_,d,32),_[0]&=248,_[31]&=127,_[31]|=64;var it=g+64;for(ee=0;ee<g;ee++)m[64+ee]=A[ee];for(ee=0;ee<32;ee++)m[32+ee]=_[32+ee];for(pe(W,m.subarray(32),g+32),Ft(W),Cn(ge,W),Je(m,ge),ee=32;ee<64;ee++)m[ee]=d[ee];for(pe(D,m,g+64),Ft(D),ee=0;ee<64;ee++)Ee[ee]=0;for(ee=0;ee<32;ee++)Ee[ee]=W[ee];for(ee=0;ee<32;ee++)for(le=0;le<32;le++)Ee[ee+le]+=D[ee]*_[le];return ct(m.subarray(32),Ee),it}function Ct(m,A){var g=t(),d=t(),_=t(),D=t(),W=t(),ee=t(),le=t();return X(m[2],o),z(m[1],A),Xe(_,m[1]),oe(D,_,c),de(_,_,m[2]),ne(D,m[2],D),Xe(W,D),Xe(ee,W),oe(le,ee,W),oe(g,le,_),oe(g,g,D),cn(g,g),oe(g,g,_),oe(g,g,D),oe(g,g,D),oe(m[0],g,D),Xe(d,m[0]),oe(d,d,D),B(d,_)&&oe(m[0],m[0],h),Xe(d,m[0]),oe(d,d,D),B(d,_)?-1:(L(m[0])===A[31]>>7&&de(m[0],s,m[0]),oe(m[3],m[0],m[1]),0)}function gt(m,A,g,d){var _,D,W=new Uint8Array(32),ee=new Uint8Array(64),le=[t(),t(),t(),t()],Ee=[t(),t(),t(),t()];if(D=-1,g<64||Ct(Ee,d))return-1;for(_=0;_<g;_++)m[_]=A[_];for(_=0;_<32;_++)m[_+32]=d[_];if(pe(ee,m,g),Ft(ee),Lt(le,Ee,ee),Cn(Ee,A.subarray(32)),we(le,Ee),Je(W,le),g-=64,S(A,0,W,0)){for(_=0;_<g;_++)m[_]=0;return-1}for(_=0;_<g;_++)m[_]=A[_+64];return D=g,D}var pn=32,kt=24,ur=32,vr=16,oi=32,Yi=32,ai=32,ci=32,mo=32,Lc=kt,fp=ur,dp=vr,Mn=64,fr=32,Nr=64,go=32,Ao=64;n.lowlevel={crypto_core_hsalsa20:C,crypto_stream_xor:w,crypto_stream:b,crypto_stream_salsa20_xor:F,crypto_stream_salsa20:v,crypto_onetimeauth:N,crypto_onetimeauth_verify:R,crypto_verify_16:E,crypto_verify_32:S,crypto_secretbox:ie,crypto_secretbox_open:j,crypto_scalarmult:Sr,crypto_scalarmult_base:xr,crypto_box_beforenm:wr,crypto_box_afternm:ii,crypto_box:si,crypto_box_open:Ir,crypto_box_keypair:On,crypto_hash:pe,crypto_sign:Ut,crypto_sign_keypair:ln,crypto_sign_open:gt,crypto_secretbox_KEYBYTES:pn,crypto_secretbox_NONCEBYTES:kt,crypto_secretbox_ZEROBYTES:ur,crypto_secretbox_BOXZEROBYTES:vr,crypto_scalarmult_BYTES:oi,crypto_scalarmult_SCALARBYTES:Yi,crypto_box_PUBLICKEYBYTES:ai,crypto_box_SECRETKEYBYTES:ci,crypto_box_BEFORENMBYTES:mo,crypto_box_NONCEBYTES:Lc,crypto_box_ZEROBYTES:fp,crypto_box_BOXZEROBYTES:dp,crypto_sign_BYTES:Mn,crypto_sign_PUBLICKEYBYTES:fr,crypto_sign_SECRETKEYBYTES:Nr,crypto_sign_SEEDBYTES:go,crypto_hash_BYTES:Ao};function Dc(m,A){if(m.length!==pn)throw new Error("bad key size");if(A.length!==kt)throw new Error("bad nonce size")}function hp(m,A){if(m.length!==ai)throw new Error("bad public key size");if(A.length!==ci)throw new Error("bad secret key size")}function un(){var m,A;for(A=0;A<arguments.length;A++)if((m=Object.prototype.toString.call(arguments[A]))!=="[object Uint8Array]")throw new TypeError("unexpected type "+m+", use Uint8Array")}function Uc(m){for(var A=0;A<m.length;A++)m[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(m){var A=new Uint8Array(m);return e(A,m),A},n.secretbox=function(m,A,g){un(m,A,g),Dc(g,A);for(var d=new Uint8Array(ur+m.length),_=new Uint8Array(d.length),D=0;D<m.length;D++)d[D+ur]=m[D];return ie(_,d,d.length,A,g),_.subarray(vr)},n.secretbox.open=function(m,A,g){un(m,A,g),Dc(g,A);for(var d=new Uint8Array(vr+m.length),_=new Uint8Array(d.length),D=0;D<m.length;D++)d[D+vr]=m[D];return d.length<32||j(_,d,d.length,A,g)!==0?!1:_.subarray(ur)},n.secretbox.keyLength=pn,n.secretbox.nonceLength=kt,n.secretbox.overheadLength=vr,n.scalarMult=function(m,A){if(un(m,A),m.length!==Yi)throw new Error("bad n size");if(A.length!==oi)throw new Error("bad p size");var g=new Uint8Array(oi);return Sr(g,m,A),g},n.scalarMult.base=function(m){if(un(m),m.length!==Yi)throw new Error("bad n size");var A=new Uint8Array(oi);return xr(A,m),A},n.scalarMult.scalarLength=Yi,n.scalarMult.groupElementLength=oi,n.box=function(m,A,g,d){var _=n.box.before(g,d);return n.secretbox(m,A,_)},n.box.before=function(m,A){un(m,A),hp(m,A);var g=new Uint8Array(mo);return wr(g,m,A),g},n.box.after=n.secretbox,n.box.open=function(m,A,g,d){var _=n.box.before(g,d);return n.secretbox.open(m,A,_)},n.box.open.after=n.secretbox.open,n.box.keyPair=function(){var m=new Uint8Array(ai),A=new Uint8Array(ci);return On(m,A),{publicKey:m,secretKey:A}},n.box.keyPair.fromSecretKey=function(m){if(un(m),m.length!==ci)throw new Error("bad secret key size");var A=new Uint8Array(ai);return xr(A,m),{publicKey:A,secretKey:new Uint8Array(m)}},n.box.publicKeyLength=ai,n.box.secretKeyLength=ci,n.box.sharedKeyLength=mo,n.box.nonceLength=Lc,n.box.overheadLength=n.secretbox.overheadLength,n.sign=function(m,A){if(un(m,A),A.length!==Nr)throw new Error("bad secret key size");var g=new Uint8Array(Mn+m.length);return Ut(g,m,m.length,A),g},n.sign.open=function(m,A){if(arguments.length!==2)throw new Error("nacl.sign.open accepts 2 arguments; did you mean to use nacl.sign.detached.verify?");if(un(m,A),A.length!==fr)throw new Error("bad public key size");var g=new Uint8Array(m.length),d=gt(g,m,m.length,A);if(d<0)return null;for(var _=new Uint8Array(d),D=0;D<_.length;D++)_[D]=g[D];return _},n.sign.detached=function(m,A){for(var g=n.sign(m,A),d=new Uint8Array(Mn),_=0;_<d.length;_++)d[_]=g[_];return d},n.sign.detached.verify=function(m,A,g){if(un(m,A,g),A.length!==Mn)throw new Error("bad signature size");if(g.length!==fr)throw new Error("bad public key size");var d=new Uint8Array(Mn+m.length),_=new Uint8Array(Mn+m.length),D;for(D=0;D<Mn;D++)d[D]=A[D];for(D=0;D<m.length;D++)d[D+Mn]=m[D];return gt(_,d,d.length,g)>=0},n.sign.keyPair=function(){var m=new Uint8Array(fr),A=new Uint8Array(Nr);return ln(m,A),{publicKey:m,secretKey:A}},n.sign.keyPair.fromSecretKey=function(m){if(un(m),m.length!==Nr)throw new Error("bad secret key size");for(var A=new Uint8Array(fr),g=0;g<A.length;g++)A[g]=m[32+g];return{publicKey:A,secretKey:new Uint8Array(m)}},n.sign.keyPair.fromSeed=function(m){if(un(m),m.length!==go)throw new Error("bad seed size");for(var A=new Uint8Array(fr),g=new Uint8Array(Nr),d=0;d<32;d++)g[d]=m[d];return ln(A,g,!0),{publicKey:A,secretKey:g}},n.sign.publicKeyLength=fr,n.sign.secretKeyLength=Nr,n.sign.seedLength=go,n.sign.signatureLength=Mn,n.hash=function(m){un(m);var A=new Uint8Array(Ao);return pe(A,m,m.length),A},n.hash.hashLength=Ao,n.verify=function(m,A){return un(m,A),m.length===0||A.length===0||m.length!==A.length?!1:y(m,0,A,0,m.length)===0},n.setPRNG=function(m){e=m},(function(){var m=typeof self<"u"?self.crypto||self.msCrypto:null;if(m&&m.getRandomValues){var A=65536;n.setPRNG(function(g,d){var _,D=new Uint8Array(d);for(_=0;_<d;_+=A)m.getRandomValues(D.subarray(_,_+Math.min(d-_,A)));for(_=0;_<d;_++)g[_]=D[_];Uc(D)})}else typeof require<"u"&&(m=require("crypto"),m&&m.randomBytes&&n.setPRNG(function(g,d){var _,D=m.randomBytes(d);for(_=0;_<d;_++)g[_]=D[_];Uc(D)}))})()})(typeof is<"u"&&is.exports?is.exports:self.nacl=self.nacl||{})});var Io=lt((rE,Xc)=>{"use strict";var So=jc().lowlevel.crypto_hash,Ln=0,hr=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 os(n,t,e){return(n[0][t[e+3]]+n[1][t[e+2]]^n[2][t[e+1]])+n[3][t[e]]}hr.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]^=os(this.S,t,0)^this.P[e],n[0]^=os(this.S,t,4)^this.P[e+1];var r=n[0];n[0]=n[1]^this.P[17],n[1]=r};hr.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]^=os(this.S,t,0)^this.P[e],n[0]^=os(this.S,t,4)^this.P[e-1];var r=n[0];n[0]=n[1]^this.P[0],n[1]=r};function dr(n,t){var e,r=0;for(e=0;e<4;e++,Ln++)Ln>=t&&(Ln=0),r=r<<8|n[Ln];return r}hr.prototype.expand0state=function(n,t){var e=new Uint32Array(2),r,i,s=new Uint8Array(e.buffer);for(r=0,Ln=0;r<18;r++)this.P[r]^=dr(n,t);for(Ln=0,r=0;r<18;r+=2)this.encipher(e,s),this.P[r]=e[0],this.P[r+1]=e[1];for(r=0;r<4;r++)for(i=0;i<256;i+=2)this.encipher(e,s),this.S[r][i]=e[0],this.S[r][i+1]=e[1]};hr.prototype.expandstate=function(n,t,e,r){var i=new Uint32Array(2),s,o;for(s=0,Ln=0;s<18;s++)this.P[s]^=dr(e,r);for(s=0,Ln=0;s<18;s+=2)i[0]^=dr(n,t),i[1]^=dr(n,t),this.encipher(i),this.P[s]=i[0],this.P[s+1]=i[1];for(s=0;s<4;s++)for(o=0;o<256;o+=2)i[0]^=dr(n,t),i[1]^=dr(n,t),this.encipher(i),this.S[s][o]=i[0],this.S[s][o+1]=i[1];Ln=0};hr.prototype.enc=function(n,t){for(var e=0;e<t;e++)this.encipher(n.subarray(e*2))};hr.prototype.dec=function(n,t){for(var e=0;e<t;e++)this.decipher(n.subarray(e*2))};var ss=8,xo=32;function wo(n,t,e){var r=new hr,i=new Uint32Array(ss),s,o=new Uint8Array([79,120,121,99,104,114,111,109,97,116,105,99,66,108,111,119,102,105,115,104,83,119,97,116,68,121,110,97,109,105,116,101]);for(r.expandstate(t,64,n,64),s=0;s<64;s++)r.expand0state(t,64),r.expand0state(n,64);for(s=0;s<ss;s++)i[s]=dr(o,o.byteLength);for(s=0;s<64;s++)r.enc(i,i.byteLength/8);for(s=0;s<ss;s++)e[4*s+3]=i[s]>>>24,e[4*s+2]=i[s]>>>16,e[4*s+1]=i[s]>>>8,e[4*s+0]=i[s]}function kp(n,t,e,r,i,s,o){var a=new Uint8Array(64),c=new Uint8Array(64),l=new Uint8Array(xo),u=new Uint8Array(xo),f=new Uint8Array(r+4),h,p,y,E,S,x,P=s;if(o<1||t===0||r===0||s===0||s>l.byteLength*l.byteLength||r>1<<20)return-1;for(E=Math.floor((s+l.byteLength-1)/l.byteLength),y=Math.floor((s+E-1)/E),h=0;h<r;h++)f[h]=e[h];for(So(a,n,t),x=1;s>0;x++){for(f[r+0]=x>>>24,f[r+1]=x>>>16,f[r+2]=x>>>8,f[r+3]=x,So(c,f,r+4),wo(a,c,u),h=l.byteLength;h--;)l[h]=u[h];for(h=1;h<o;h++)for(So(c,u,u.byteLength),wo(a,c,u),p=0;p<l.byteLength;p++)l[p]^=u[p];for(y=Math.min(y,s),h=0;h<y&&(S=h*E+(x-1),!(S>=P));h++)i[S]=l[h];s-=h}return 0}Xc.exports={BLOCKS:ss,HASHSIZE:xo,hash:wo,pbkdf:kp}});var Un=lt((iE,cs)=>{"use strict";var Dn=require("crypto"),Or;try{Or=require("cpu-features")()}catch{}var{bindingAvailable:Jc,CIPHER_INFO:vp,MAC_INFO:Np}=Gn(),Zc=(()=>{if(typeof Dn.sign=="function"&&typeof Dn.verify=="function"){let n=`-----BEGIN PRIVATE KEY-----\r
3
3
  MC4CAQAwBQYDK2VwBCIEIHKj+sVa9WcD/q2DJUJaf43Kptc8xYuUQA4bOFj9vC8T\r
4
- -----END PRIVATE KEY-----`,t=Buffer.from("a"),e,r;try{e=Dn.sign(null,t,n),r=Dn.verify(null,t,n,e)}catch{}return Buffer.isBuffer(e)&&e.length===64&&r===!0}return!1})(),Jc=typeof Dn.diffieHellman=="function"&&typeof Dn.generateKeyPairSync=="function"&&typeof Dn.createPublicKey=="function",os=["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"];Jc&&(os.unshift("curve25519-sha256"),os.unshift("curve25519-sha256@libssh.org"));var vp=os.concat(["diffie-hellman-group-exchange-sha1","diffie-hellman-group14-sha1","diffie-hellman-group1-sha1"]),wo=["ecdsa-sha2-nistp256","ecdsa-sha2-nistp384","ecdsa-sha2-nistp521","rsa-sha2-512","rsa-sha2-256","ssh-rsa"];Xc&&wo.unshift("ssh-ed25519");var Np=wo.concat(["ssh-dss"]),Zc=(()=>{let n=Dn.getCiphers();return t=>n.includes(Cp[t].sslName)})(),zn=["aes128-gcm@openssh.com","aes256-gcm@openssh.com","aes128-ctr","aes192-ctr","aes256-ctr"];Tr&&Tr.flags&&!Tr.flags.aes?jc?zn.unshift("chacha20-poly1305@openssh.com"):zn.push("chacha20-poly1305@openssh.com"):jc&&Tr&&Tr.arch==="x86"?zn.splice(4,0,"chacha20-poly1305@openssh.com"):zn.push("chacha20-poly1305@openssh.com");zn=zn.filter(Zc);var Bp=zn.concat(["aes256-cbc","aes192-cbc","aes128-cbc","blowfish-cbc","3des-cbc","aes128-gcm","aes256-gcm","arcfour256","arcfour128","cast128-cbc","arcfour"].filter(Zc)),el=(()=>{let n=Dn.getHashes();return t=>n.includes(kp[t].sslName)})(),tl=["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(el),Rp=tl.concat(["hmac-md5","hmac-sha2-256-96","hmac-sha2-512-96","hmac-ripemd160","hmac-sha1-96","hmac-md5-96"].filter(el)),nl=["none","zlib@openssh.com","zlib"],Pp=nl.concat([]),Pr={BAD_DHGEX:1,OLD_EXIT:2,DYN_RPORT_BUG:4,BUG_DHGEX_LARGE:8,IMPLY_RSA_SHA2_SIGALGS:16};as.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:os,SUPPORTED_KEX:vp,DEFAULT_SERVER_HOST_KEY:wo,SUPPORTED_SERVER_HOST_KEY:Np,DEFAULT_CIPHER:zn,SUPPORTED_CIPHER:Bp,DEFAULT_MAC:tl,SUPPORTED_MAC:Rp,DEFAULT_COMPRESSION:nl,SUPPORTED_COMPRESSION:Pp,curve25519Supported:Jc,eddsaSupported:Xc};as.exports.DISCONNECT_REASON_BY_VALUE=Array.from(Object.entries(as.exports.DISCONNECT_REASON)).reduce((n,[t,e])=>({...n,[e]:t}),{})});var En=lt((nE,ol)=>{"use strict";var An=li().Ber,cs,sl=Buffer[Symbol.species],Tp=Object.getPrototypeOf(Uint8Array.prototype).fill;function rl(n,t){return n[t++]*16777216+n[t++]*65536+n[t++]*256+n[t]}function ui(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 fi(n,t,e){return e===void 0&&(e=n.length),new sl(n.buffer,n.byteOffset+t,e-t)}function Co(){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)?ui(t,r,n,n+=i):t.utf8Slice(n,n+=i):fi(t,n,n+=i)},readRaw:r=>{if(t){if(typeof r!="number")return fi(t,n,n+=t.length-n);if(t.length-n>=r)return fi(t,n,n+=r)}}};return e}function il(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 Io(n,t,e){return n[e++]=t>>>24,n[e++]=t>>>16,n[e++]=t>>>8,n[e++]=t,e}var ls=Co();ol.exports={bufferCopy:ui,bufferSlice:fi,FastBuffer:sl,bufferFill:(n,t,e,r)=>Tp.call(n,t,e,r),makeError:il,doFatalError:(n,t,e,r)=>{let s;return cs===void 0&&({DISCONNECT_REASON:cs}=Un()),t instanceof Error?(s=t,typeof e!="number"?r=cs.PROTOCOL_ERROR:r=e):s=il(t,e,!0),typeof r!="number"&&(r=cs.PROTOCOL_ERROR),n.disconnect(r),n._destruct(),n._onError(s),1/0},readUInt32BE:rl,writeUInt32BE:Io,writeUInt32LE:(n,t,e)=>(n[e++]=t,n[e++]=t>>>8,n[e++]=t>>>16,n[e++]=t>>>24,e),makeBufferParser:Co,bufferParser:Co(),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=rl(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)?ui(n,e,t,o):n.utf8Slice(t,o):fi(n,t,o)},sigSSHToASN1:(n,t)=>{switch(t){case"ssh-dss":{if(n.length>40)return n;let e=new An.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,An.Integer),e.writeBuffer(s,An.Integer),e.endSequence(),e.buffer}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{ls.init(n,0);let e=ls.readString(),r=ls.readString();if(ls.clear(),e===void 0||r===void 0)return;let s=new An.Writer;return s.startSequence(),s.writeBuffer(e,An.Integer),s.writeBuffer(r,An.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 An.Reader(n);e.readSequence();let r=e.readString(An.Integer,!0),s=e.readString(An.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 ui(r,a,i,r.length,0),ui(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 An.Reader(n);e.readSequence();let r=e.readString(An.Integer,!0),s=e.readString(An.Integer,!0);if(r===null||s===null)return;let i=Buffer.allocUnsafe(4+r.length+4+s.length);return Io(i,r.length,0),i.set(r,4),Io(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 al=lt((us,vo)=>{var ko=(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,pe){r=J,s=pe});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",u="",f,h,p,y,E;l?(u=c?require("path").dirname(u)+"/":__dirname+"/",f=function(J,pe){var we=On(J);return we?pe?we:we.toString():(y||(y=require("fs")),E||(E=require("path")),J=E.normalize(J),y.readFileSync(J,pe?null:"utf8"))},p=function(J){return J=f(J,!0),J.buffer||(J=new Uint8Array(J)),$(J.buffer),J},h=function(J,pe,we){var Oe=On(J);Oe&&pe(Oe),y||(y=require("fs")),E||(E=require("path")),J=E.normalize(J),y.readFile(J,function(Je,Lt){Je?we(Je):pe(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?u=self.location.href:typeof document<"u"&&document.currentScript&&(u=document.currentScript.src),n&&(u=n),u.indexOf("blob:")!==0?u=u.substr(0,u.lastIndexOf("/")+1):u="",f=function(J){try{var pe=new XMLHttpRequest;return pe.open("GET",J,!1),pe.send(null),pe.responseText}catch(Je){if(J=On(J)){pe=[];for(var we=0;we<J.length;we++){var Oe=J[we];255<Oe&&(br&&$(!1,"Character code "+Oe+" ("+String.fromCharCode(Oe)+") at offset "+we+" not in 0x00-0xFF."),Oe&=255),pe.push(String.fromCharCode(Oe))}return pe.join("")}throw Je}},c&&(p=function(J){try{var pe=new XMLHttpRequest;return pe.open("GET",J,!1),pe.responseType="arraybuffer",pe.send(null),new Uint8Array(pe.response)}catch(we){if(J=On(J))return J;throw we}}),h=function(J,pe,we){var Oe=new XMLHttpRequest;Oe.open("GET",J,!0),Oe.responseType="arraybuffer",Oe.onload=function(){if(Oe.status==200||Oe.status==0&&Oe.response)pe(Oe.response);else{var Je=On(J);Je?pe(Je.buffer):we()}},Oe.onerror=we,Oe.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 P=e.noExitRuntime||!0;typeof WebAssembly!="object"&&z("no native wasm support detected");var q,C=!1;function $(J,pe){J||z("Assertion failed: "+pe)}function F(J){var pe=e["_"+J];return $(pe,"Cannot call unknown function "+J+", make sure it is exported"),pe}function v(J,pe,we,Oe){var Je={string:function(ct){var Ft=0;if(ct!=null&&ct!==0){var Ut=(ct.length<<2)+1;Ft=ii(Ut);var Ct=Ft,gt=N;if(0<Ut){Ut=Ct+Ut-1;for(var pn=0;pn<ct.length;++pn){var kt=ct.charCodeAt(pn);if(55296<=kt&&57343>=kt){var lr=ct.charCodeAt(++pn);kt=65536+((kt&1023)<<10)|lr&1023}if(127>=kt){if(Ct>=Ut)break;gt[Ct++]=kt}else{if(2047>=kt){if(Ct+1>=Ut)break;gt[Ct++]=192|kt>>6}else{if(65535>=kt){if(Ct+2>=Ut)break;gt[Ct++]=224|kt>>12}else{if(Ct+3>=Ut)break;gt[Ct++]=240|kt>>18,gt[Ct++]=128|kt>>12&63}gt[Ct++]=128|kt>>6&63}gt[Ct++]=128|kt&63}}gt[Ct]=0}}return Ft},array:function(ct){var Ft=ii(ct.length);return k.set(ct,Ft),Ft}},Lt=F(J),Cn=[];if(J=0,Oe)for(var ln=0;ln<Oe.length;ln++){var Cr=Je[we[ln]];Cr?(J===0&&(J=ri()),Cn[ln]=Cr(Oe[ln])):Cn[ln]=Oe[ln]}return we=Lt.apply(null,Cn),we=(function(ct){if(pe==="string")if(ct){for(var Ft=N,Ut=ct+NaN,Ct=ct;Ft[Ct]&&!(Ct>=Ut);)++Ct;if(16<Ct-ct&&Ft.subarray&&b)ct=b.decode(Ft.subarray(ct,Ct));else{for(Ut="";ct<Ct;){var gt=Ft[ct++];if(gt&128){var pn=Ft[ct++]&63;if((gt&224)==192)Ut+=String.fromCharCode((gt&31)<<6|pn);else{var kt=Ft[ct++]&63;gt=(gt&240)==224?(gt&15)<<12|pn<<6|kt:(gt&7)<<18|pn<<12|kt<<6|Ft[ct++]&63,65536>gt?Ut+=String.fromCharCode(gt):(gt-=65536,Ut+=String.fromCharCode(55296|gt>>10,56320|gt&1023))}}else Ut+=String.fromCharCode(gt)}ct=Ut}}else ct="";else ct=pe==="boolean"?!!ct:ct;return ct})(we),J!==0&&zi(J),we}var b=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,w,k,N;function R(){var J=q.buffer;w=J,e.HEAP8=k=new Int8Array(J),e.HEAP16=new Int16Array(J),e.HEAP32=new Int32Array(J),e.HEAPU8=N=new Uint8Array(J),e.HEAPU16=new Uint16Array(J),e.HEAPU32=new Uint32Array(J),e.HEAPF32=new Float32Array(J),e.HEAPF64=new Float64Array(J)}var ie,j=[],X=[],re=[];function fe(){var J=e.preRun.shift();j.unshift(J)}var H=0,B=null,L=null;e.preloadedImages={},e.preloadedAudios={};function z(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 ne="data:application/octet-stream;base64,",de;if(de="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==",!de.startsWith(ne)){var oe=de;de=e.locateFile?e.locateFile(oe,u):u+oe}function Xe(){var J=de;try{if(J==de&&x)return new Uint8Array(x);var pe=On(J);if(pe)return pe;if(p)return p(J);throw"both async and sync fetching of the wasm failed"}catch(we){z(we)}}function dt(){if(!x&&(a||c)){if(typeof fetch=="function"&&!de.startsWith("file://"))return fetch(de,{credentials:"same-origin"}).then(function(J){if(!J.ok)throw"failed to load wasm binary file at '"+de+"'";return J.arrayBuffer()}).catch(function(){return Xe()});if(h)return new Promise(function(J,pe){h(de,function(we){J(new Uint8Array(we))},pe)})}return Promise.resolve().then(function(){return Xe()})}function cn(J){for(;0<J.length;){var pe=J.shift();if(typeof pe=="function")pe(e);else{var we=pe.m;typeof we=="number"?pe.l===void 0?ie.get(we)():ie.get(we)(pe.l):we(pe.l===void 0?null:pe.l)}}}var br=!1,Sr=typeof atob=="function"?atob:function(J){var pe="",we=0;J=J.replace(/[^A-Za-z0-9\+\/=]/g,"");do{var Oe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(J.charAt(we++)),Je="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(J.charAt(we++)),Lt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(J.charAt(we++)),Cn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(J.charAt(we++));Oe=Oe<<2|Je>>4,Je=(Je&15)<<4|Lt>>2;var ln=(Lt&3)<<6|Cn;pe+=String.fromCharCode(Oe),Lt!==64&&(pe+=String.fromCharCode(Je)),Cn!==64&&(pe+=String.fromCharCode(ln))}while(we<J.length);return pe};function On(J){if(J.startsWith(ne)){if(J=J.slice(ne.length),typeof l=="boolean"&&l){var pe=Buffer.from(J,"base64");pe=new Uint8Array(pe.buffer,pe.byteOffset,pe.byteLength)}else try{var we=Sr(J),Oe=new Uint8Array(we.length);for(J=0;J<we.length;++J)Oe[J]=we.charCodeAt(J);pe=Oe}catch{throw Error("Converting base64 string to bytes failed.")}return pe}}var xr={a:function(J){var pe=N.length;if(J>>>=0,2147483648<J)return!1;for(var we=1;4>=we;we*=2){var Oe=pe*(1+.2/we);Oe=Math.min(Oe,J+100663296),Oe=Math.max(J,Oe),0<Oe%65536&&(Oe+=65536-Oe%65536);e:{try{q.grow(Math.min(2147483648,Oe)-w.byteLength+65535>>>16),R();var Je=1;break e}catch{}Je=void 0}if(Je)return!0}return!1}};(function(){function J(Je){e.asm=Je.exports,q=e.asm.b,R(),ie=e.asm.j,X.unshift(e.asm.c),H--,e.monitorRunDependencies&&e.monitorRunDependencies(H),H==0&&(B!==null&&(clearInterval(B),B=null),L&&(Je=L,L=null,Je()))}function pe(Je){J(Je.instance)}function we(Je){return dt().then(function(Lt){return WebAssembly.instantiate(Lt,Oe)}).then(Je,function(Lt){S("failed to asynchronously prepare wasm: "+Lt),z(Lt)})}var Oe={a:xr};if(H++,e.monitorRunDependencies&&e.monitorRunDependencies(H),e.instantiateWasm)try{return e.instantiateWasm(Oe,J)}catch(Je){return S("Module.instantiateWasm callback failed with error: "+Je),!1}return(function(){return x||typeof WebAssembly.instantiateStreaming!="function"||de.startsWith(ne)||de.startsWith("file://")||typeof fetch!="function"?we(pe):fetch(de,{credentials:"same-origin"}).then(function(Je){return WebAssembly.instantiateStreaming(Je,Oe).then(pe,function(Lt){return S("wasm streaming compile failed: "+Lt),S("falling back to ArrayBuffer instantiation"),we(pe)})})})().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 ri=e.stackSave=function(){return(ri=e.stackSave=e.asm.e).apply(null,arguments)},zi=e.stackRestore=function(){return(zi=e.stackRestore=e.asm.f).apply(null,arguments)},ii=e.stackAlloc=function(){return(ii=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,pe,we,Oe){we=we||[];var Je=we.every(function(Lt){return Lt==="number"});return pe!=="string"&&Je&&!Oe?F(J):function(){return v(J,pe,we,arguments)}};var wr;L=function J(){wr||Ir(),wr||(L=J)};function Ir(){function J(){if(!wr&&(wr=!0,e.calledRun=!0,!C)){if(cn(X),r(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;){var pe=e.postRun.shift();re.unshift(pe)}cn(re)}}if(!(0<H)){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)fe();cn(j),0<H||(e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),J()},1)):J())}}if(e.run=Ir,e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);0<e.preInit.length;)e.preInit.pop()();return Ir(),t.ready})})();typeof us=="object"&&typeof vo=="object"?vo.exports=ko:typeof define=="function"&&define.amd?define([],function(){return ko}):typeof us=="object"&&(us.createPoly1305=ko)});var Gn=lt((rE,dl)=>{"use strict";var{createCipheriv:Mr,createDecipheriv:fs,createHmac:No,randomFillSync:hr,timingSafeEqual:Bo}=require("crypto"),{readUInt32BE:hi,writeUInt32BE:fn}=En(),Yn=Buffer[Symbol.species],cl=2**32-1,ll=Buffer.alloc(0),Or=Buffer.alloc(4),ds=new Map,pr=35e3,Ro,Vo,zo,Go,Yo,jo,Xo;try{Ro=require("./crypto/build/Release/sshcrypto.node"),{AESGCMCipher:Vo,ChaChaPolyCipher:zo,GenericCipher:Go,AESGCMDecipher:Yo,ChaChaPolyDecipher:jo,GenericDecipher:Xo}=Ro}catch{}var qt=1,Op=(()=>{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)}})(),Mp=(()=>{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)}})(),Po=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,hr(s,5+t,r),s}encrypt(t){this._dead||(this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},ul=Buffer.alloc(32),nn=Buffer.alloc(16),di,pi,Jo,To=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encKeyMain=e.cipherKey.slice(0,32),this._encKeyPktLen=e.cipherKey.slice(32),this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,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,hr(s,5+t,r),s}encrypt(t){if(this._dead)return;nn[0]=0,fn(nn,this.outSeqno,12);let e=Mr("chacha20",this._encKeyMain,nn).update(ul),r=Mr("chacha20",this._encKeyPktLen,nn).update(t.slice(0,4));this._onWrite(r),nn[0]=1;let s=Mr("chacha20",this._encKeyMain,nn).update(t.slice(4));this._onWrite(s),Jo(pi,r,r.length,s,s.length,e);let i=Buffer.allocUnsafe(16);i.set(new Uint8Array(di.HEAPU8.buffer,pi,16),0),this._onWrite(i),this.outSeqno=this.outSeqno+1>>>0}},Oo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new zo(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,hr(s,5+t,r),s}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Mo=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,hr(s,5+t,r),s}encrypt(t){if(this._dead)return;let e=Mr(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),fl(this._encIV),this.outSeqno=this.outSeqno+1>>>0}},Lo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new Vo(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,hr(s,5+t,r),s}encrypt(t){this._dead||(this._instance.encrypt(t),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Do=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encBlockLen=e.cipherInfo.blockLen,this._cipherInstance=Mr(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=ds.get(r);s===void 0&&(s=Buffer.alloc(r),ds.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,hr(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=No(this._macSSLName,this._macKey),fn(Or,this.outSeqno,0),e.update(Or),e.update(s),e.update(i)}else{let s=this._cipherInstance.update(t);this._onWrite(s),e=No(this._macSSLName,this._macKey),fn(Or,this.outSeqno,0),e.update(Or),e.update(t)}let r=e.digest();r.length>this._macActualLen&&(r=r.slice(0,this._macActualLen)),this._onWrite(r),this.outSeqno=this.outSeqno+1>>>0}},Uo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encBlockLen=e.cipherInfo.blockLen,this._macLen=e.macInfo.len,this._macActualLen=e.macInfo.actualLen,this._aadLen=e.macInfo.isETM?4:0,this._instance=new Go(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,hr(i,5+t,s),i}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._macActualLen<this._macLen&&(t=new Yn(t.buffer,t.byteOffset,t.length-(this._macLen-this._macActualLen))),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},$o=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>pr||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 Yn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):ll;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}}}},Fo=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;nn[0]=0,fn(nn,this.inSeqno,12);let c=fs("chacha20",this._decKeyPktLen,nn).update(this._lenBuf);if(this._len=hi(c,0),this._len>pr||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}nn[0]=0,fn(nn,this.inSeqno,12);let s=Mr("chacha20",this._decKeyMain,nn).update(ul);if(Jo(pi,this._lenBuf,4,this._packet,this._packet.length,s),this._calcMac.set(new Uint8Array(di.HEAPU8.buffer,pi,16),0),!Bo(this._calcMac,this._mac))throw new Error("Invalid MAC");nn[0]=1;let i=fs("chacha20",this._decKeyMain,nn).update(this._packet),o=new Yn(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}}}},Ho=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new jo(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>pr||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 Yn(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}}}},Qo=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>pr||this._len<16||(this._len&15)!==0)throw new Error("Bad packet length");this._decipherInstance=fs(this._decipherSSLName,this._decipherKey,this._decipherIV),this._decipherInstance.setAutoPadding(!1),this._decipherInstance.setAAD(Lp(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 Yn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):ll;this.inSeqno=this.inSeqno+1>>>0,fl(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}}}},Wo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new Yo(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>pr||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 Yn(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}}}},qo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decipherInstance=fs(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=ds.get(r);s===void 0&&(s=Buffer.alloc(r),ds.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=hi(this._block,0):(a=this._decipherInstance.update(this._block),this._len=hi(a,0),c=4+this._len-this._blockSize),this._len>pr||this._len<5||(c&this._blockSize-1)!==0)throw new Error("Bad packet length");if(this._macInstance=No(this._macSSLName,this._macKey),fn(Or,this.inSeqno,0),this._macInstance.update(Or),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)),!Dp(s,this._mac))throw new Error("Invalid MAC");let i=new Yn(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}}}},Ko=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new Xo(e.decipherInfo.sslName,e.decipherKey,e.decipherIV,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=hi(this._block,0):(this._instance.decryptBlock(this._block),this._len=hi(this._block,0),o=4+this._len-this._block.length),this._len>pr||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 Yn(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 fl(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 Lp=(()=>{let n=Buffer.alloc(4);return t=>(n[0]=t>>>24,n[1]=t>>>16,n[2]=t>>>8,n[3]=t,n)})();function Dp(n,t){return n.length!==t.length?(Bo(n,n),!1):Bo(n,t)}function Up(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>cl)throw new Error("Invalid outbound.seqno");let e=!!t.forceNative;switch(t.cipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return Vo&&!e?new Lo(n):new Mo(n);case"chacha20":return zo&&!e?new Oo(n):new To(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 Go&&!e?new Uo(n):new Do(n)}}}function $p(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>cl)throw new Error("Invalid inbound.seqno");let e=!!t.forceNative;switch(t.decipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return Yo&&!e?new Wo(n):new Qo(n);case"chacha20":return jo&&!e?new Ho(n):new Fo(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 Xo&&!e?new Ko(n):new qo(n)}}}dl.exports={CIPHER_INFO:Op,MAC_INFO:Mp,bindingAvailable:!!Ro,init:new Promise(async(n,t)=>{try{di=await al()(),pi=di._malloc(16),Jo=di.cwrap("poly1305_auth",null,["number","array","number","array","number","array"])}catch(e){return t(e)}n()}),NullCipher:Po,createCipher:Up,NullDecipher:$o,createDecipher:$p}});var Xn=lt((iE,Sl)=>{"use strict";var{createDecipheriv:ea,createECDH:Fp,createHash:gi,createHmac:Hp,createSign:Qp,createVerify:Wp,getCiphers:qp,sign:hl,verify:pl}=require("crypto"),Kp=qp(),{Ber:Re}=li(),Vp=xo().pbkdf,{CIPHER_INFO:Ai}=Gn(),{eddsaSupported:ta,SUPPORTED_CIPHER:zp}=Un(),{bufferSlice:mr,makeBufferParser:Gp,readString:Ne,readUInt32BE:mi,writeUInt32BE:Ht}=En(),$n=Symbol("Hash Algorithm"),_n=Symbol("Private key PEM"),kn=Symbol("Public key PEM"),jn=Symbol("Public key SSH"),Lr=Symbol("Decrypted Key"),Zo=Object.create(null);{let n=Object.keys(Ai);for(let t=0;t<n.length;++t){let e=Ai[n[t]].sslName;!e||Zo[e]||(Zo[e]=Ai[n[t]])}}var hs=Gp();function bn(n,t){t=t.base64Slice(0,t.length);let e=t.replace(/.{64}/g,`$&
4
+ -----END PRIVATE KEY-----`,t=Buffer.from("a"),e,r;try{e=Dn.sign(null,t,n),r=Dn.verify(null,t,n,e)}catch{}return Buffer.isBuffer(e)&&e.length===64&&r===!0}return!1})(),el=typeof Dn.diffieHellman=="function"&&typeof Dn.generateKeyPairSync=="function"&&typeof Dn.createPublicKey=="function",as=["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"];el&&(as.unshift("curve25519-sha256"),as.unshift("curve25519-sha256@libssh.org"));var Bp=as.concat(["diffie-hellman-group-exchange-sha1","diffie-hellman-group14-sha1","diffie-hellman-group1-sha1"]),Co=["ecdsa-sha2-nistp256","ecdsa-sha2-nistp384","ecdsa-sha2-nistp521","rsa-sha2-512","rsa-sha2-256","ssh-rsa"];Zc&&Co.unshift("ssh-ed25519");var Rp=Co.concat(["ssh-dss"]),tl=(()=>{let n=Dn.getCiphers();return t=>n.includes(vp[t].sslName)})(),zn=["aes128-gcm@openssh.com","aes256-gcm@openssh.com","aes128-ctr","aes192-ctr","aes256-ctr"];Or&&Or.flags&&!Or.flags.aes?Jc?zn.unshift("chacha20-poly1305@openssh.com"):zn.push("chacha20-poly1305@openssh.com"):Jc&&Or&&Or.arch==="x86"?zn.splice(4,0,"chacha20-poly1305@openssh.com"):zn.push("chacha20-poly1305@openssh.com");zn=zn.filter(tl);var Pp=zn.concat(["aes256-cbc","aes192-cbc","aes128-cbc","blowfish-cbc","3des-cbc","aes128-gcm","aes256-gcm","arcfour256","arcfour128","cast128-cbc","arcfour"].filter(tl)),nl=(()=>{let n=Dn.getHashes();return t=>n.includes(Np[t].sslName)})(),rl=["hmac-sha2-256-etm@openssh.com","hmac-sha2-512-etm@openssh.com","hmac-sha1-etm@openssh.com","hmac-sha2-256","hmac-sha2-512","hmac-sha1"].filter(nl),Tp=rl.concat(["hmac-md5","hmac-sha2-256-96","hmac-sha2-512-96","hmac-ripemd160","hmac-sha1-96","hmac-md5-96"].filter(nl)),il=["none","zlib@openssh.com","zlib"],Op=il.concat([]),Tr={BAD_DHGEX:1,OLD_EXIT:2,DYN_RPORT_BUG:4,BUG_DHGEX_LARGE:8,IMPLY_RSA_SHA2_SIGALGS:16};cs.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:Tr,COMPAT_CHECKS:[["Cisco-1.25",Tr.BAD_DHGEX],[/^Cisco-1[.]/,Tr.BUG_DHGEX_LARGE],[/^[0-9.]+$/,Tr.OLD_EXIT],[/^OpenSSH_5[.][0-9]+/,Tr.DYN_RPORT_BUG],[/^OpenSSH_7[.]4/,Tr.IMPLY_RSA_SHA2_SIGALGS]],DEFAULT_KEX:as,SUPPORTED_KEX:Bp,DEFAULT_SERVER_HOST_KEY:Co,SUPPORTED_SERVER_HOST_KEY:Rp,DEFAULT_CIPHER:zn,SUPPORTED_CIPHER:Pp,DEFAULT_MAC:rl,SUPPORTED_MAC:Tp,DEFAULT_COMPRESSION:il,SUPPORTED_COMPRESSION:Op,curve25519Supported:el,eddsaSupported:Zc};cs.exports.DISCONNECT_REASON_BY_VALUE=Array.from(Object.entries(cs.exports.DISCONNECT_REASON)).reduce((n,[t,e])=>({...n,[e]:t}),{})});var En=lt((sE,cl)=>{"use strict";var An=ui().Ber,ls,al=Buffer[Symbol.species],Mp=Object.getPrototypeOf(Uint8Array.prototype).fill;function sl(n,t){return n[t++]*16777216+n[t++]*65536+n[t++]*256+n[t]}function fi(n,t,e,r,i){i||(i=0),r>n.length&&(r=n.length);let s=r-e,o=t.length-i;return s>o&&(s=o),t.set(new Uint8Array(n.buffer,n.byteOffset+e,s),i),s}function di(n,t,e){return e===void 0&&(e=n.length),new al(n.buffer,n.byteOffset+t,e-t)}function vo(){let n=0,t,e={init:(r,i)=>{t=r,n=typeof i=="number"?i:0},pos:()=>n,length:()=>t?t.length:0,avail:()=>t&&n<t.length?t.length-n:0,clear:()=>{t=void 0},readUInt32BE:()=>{if(!(!t||n+3>=t.length))return t[n++]*16777216+t[n++]*65536+t[n++]*256+t[n++]},readUInt64BE:r=>{if(!(!t||n+7>=t.length))switch(r){case"always":return BigInt(`0x${t.hexSlice(n,n+=8)}`);case"maybe":if(t[n]>31)return BigInt(`0x${t.hexSlice(n,n+=8)}`);default:return t[n++]*72057594037927940+t[n++]*281474976710656+t[n++]*1099511627776+t[n++]*4294967296+t[n++]*16777216+t[n++]*65536+t[n++]*256+t[n++]}},skip:r=>{t&&r>0&&(n+=r)},skipString:()=>{let r=e.readUInt32BE();if(r!==void 0)return n+=r,n<=t.length?r:void 0},readByte:()=>{if(t&&n<t.length)return t[n++]},readBool:()=>{if(t&&n<t.length)return!!t[n++]},readList:()=>{let r=e.readString(!0);if(r!==void 0)return r?r.split(","):[]},readString:(r,i)=>{typeof r=="number"&&(i=r,r=void 0);let s=e.readUInt32BE();if(s!==void 0&&!(t.length-n<s||typeof i=="number"&&s>i))return r?Buffer.isBuffer(r)?fi(t,r,n,n+=s):t.utf8Slice(n,n+=s):di(t,n,n+=s)},readRaw:r=>{if(t){if(typeof r!="number")return di(t,n,n+=t.length-n);if(t.length-n>=r)return di(t,n,n+=r)}}};return e}function ol(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 ko(n,t,e){return n[e++]=t>>>24,n[e++]=t>>>16,n[e++]=t>>>8,n[e++]=t,e}var us=vo();cl.exports={bufferCopy:fi,bufferSlice:di,FastBuffer:al,bufferFill:(n,t,e,r)=>Mp.call(n,t,e,r),makeError:ol,doFatalError:(n,t,e,r)=>{let i;return ls===void 0&&({DISCONNECT_REASON:ls}=Un()),t instanceof Error?(i=t,typeof e!="number"?r=ls.PROTOCOL_ERROR:r=e):i=ol(t,e,!0),typeof r!="number"&&(r=ls.PROTOCOL_ERROR),n.disconnect(r),n._destruct(),n._onError(i),1/0},readUInt32BE:sl,writeUInt32BE:ko,writeUInt32LE:(n,t,e)=>(n[e++]=t,n[e++]=t>>>8,n[e++]=t>>>16,n[e++]=t>>>24,e),makeBufferParser:vo,bufferParser:vo(),readString:(n,t,e,r)=>{typeof e=="number"&&(r=e,e=void 0),t===void 0&&(t=0);let i=n.length-t;if(t<0||t>=n.length||i<4)return;let s=sl(n,t);if(i<4+s||typeof r=="number"&&s>r)return;t+=4;let o=t+s;return n._pos=o,e?Buffer.isBuffer(e)?fi(n,e,t,o):n.utf8Slice(t,o):di(n,t,o)},sigSSHToASN1:(n,t)=>{switch(t){case"ssh-dss":{if(n.length>40)return n;let e=new An.Writer;e.startSequence();let r=n.slice(0,20),i=n.slice(20);if(r[0]&128){let s=Buffer.allocUnsafe(21);s[0]=0,r.copy(s,1),r=s}else r[0]===0&&!(r[1]&128)&&(r=r.slice(1));if(i[0]&128){let s=Buffer.allocUnsafe(21);s[0]=0,i.copy(s,1),i=s}else i[0]===0&&!(i[1]&128)&&(i=i.slice(1));return e.writeBuffer(r,An.Integer),e.writeBuffer(i,An.Integer),e.endSequence(),e.buffer}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{us.init(n,0);let e=us.readString(),r=us.readString();if(us.clear(),e===void 0||r===void 0)return;let i=new An.Writer;return i.startSequence(),i.writeBuffer(e,An.Integer),i.writeBuffer(r,An.Integer),i.endSequence(),i.buffer}default:return n}},convertSignature:(n,t)=>{switch(t){case"ssh-dss":{if(n.length<=40)return n;let e=new An.Reader(n);e.readSequence();let r=e.readString(An.Integer,!0),i=e.readString(An.Integer,!0),s=0,o=0;if(r.length<20){let c=Buffer.allocUnsafe(20);c.set(r,1),r=c,r[0]=0}if(i.length<20){let c=Buffer.allocUnsafe(20);c.set(i,1),i=c,i[0]=0}r.length>20&&r[0]===0&&(s=1),i.length>20&&i[0]===0&&(o=1);let a=Buffer.allocUnsafe(r.length-s+(i.length-o));return fi(r,a,s,r.length,0),fi(i,a,o,i.length,r.length-s),a}case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":{if(n[0]===0)return n;let e=new An.Reader(n);e.readSequence();let r=e.readString(An.Integer,!0),i=e.readString(An.Integer,!0);if(r===null||i===null)return;let s=Buffer.allocUnsafe(4+r.length+4+i.length);return ko(s,r.length,0),s.set(r,4),ko(s,i.length,4+r.length),s.set(i,8+r.length),s}}return n},sendPacket:(n,t,e)=>!e&&n._kexinit!==void 0?(n._queue===void 0&&(n._queue=[]),n._queue.push(t),n._debug&&n._debug("Outbound: ... packet queued"),!1):(n._cipher.encrypt(t),!0)}});var ll=lt((fs,Bo)=>{var No=(function(){var n=typeof document<"u"&&document.currentScript?document.currentScript.src:void 0;return typeof __filename<"u"&&(n=n||__filename),(function(t){t=t||{};var e;e||(e=typeof t<"u"?t:{});var r,i;e.ready=new Promise(function(J,pe){r=J,i=pe});var s={},o;for(o in e)e.hasOwnProperty(o)&&(s[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",u="",f,h,p,y,E;l?(u=c?require("path").dirname(u)+"/":__dirname+"/",f=function(J,pe){var we=On(J);return we?pe?we:we.toString():(y||(y=require("fs")),E||(E=require("path")),J=E.normalize(J),y.readFileSync(J,pe?null:"utf8"))},p=function(J){return J=f(J,!0),J.buffer||(J=new Uint8Array(J)),$(J.buffer),J},h=function(J,pe,we){var Oe=On(J);Oe&&pe(Oe),y||(y=require("fs")),E||(E=require("path")),J=E.normalize(J),y.readFile(J,function(Je,Lt){Je?we(Je):pe(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?u=self.location.href:typeof document<"u"&&document.currentScript&&(u=document.currentScript.src),n&&(u=n),u.indexOf("blob:")!==0?u=u.substr(0,u.lastIndexOf("/")+1):u="",f=function(J){try{var pe=new XMLHttpRequest;return pe.open("GET",J,!1),pe.send(null),pe.responseText}catch(Je){if(J=On(J)){pe=[];for(var we=0;we<J.length;we++){var Oe=J[we];255<Oe&&(Sr&&$(!1,"Character code "+Oe+" ("+String.fromCharCode(Oe)+") at offset "+we+" not in 0x00-0xFF."),Oe&=255),pe.push(String.fromCharCode(Oe))}return pe.join("")}throw Je}},c&&(p=function(J){try{var pe=new XMLHttpRequest;return pe.open("GET",J,!1),pe.responseType="arraybuffer",pe.send(null),new Uint8Array(pe.response)}catch(we){if(J=On(J))return J;throw we}}),h=function(J,pe,we){var Oe=new XMLHttpRequest;Oe.open("GET",J,!0),Oe.responseType="arraybuffer",Oe.onload=function(){if(Oe.status==200||Oe.status==0&&Oe.response)pe(Oe.response);else{var Je=On(J);Je?pe(Je.buffer):we()}},Oe.onerror=we,Oe.send(null)}),e.print||console.log.bind(console);var S=e.printErr||console.warn.bind(console);for(o in s)s.hasOwnProperty(o)&&(e[o]=s[o]);s=null;var x;e.wasmBinary&&(x=e.wasmBinary);var P=e.noExitRuntime||!0;typeof WebAssembly!="object"&&z("no native wasm support detected");var q,C=!1;function $(J,pe){J||z("Assertion failed: "+pe)}function F(J){var pe=e["_"+J];return $(pe,"Cannot call unknown function "+J+", make sure it is exported"),pe}function v(J,pe,we,Oe){var Je={string:function(ct){var Ft=0;if(ct!=null&&ct!==0){var Ut=(ct.length<<2)+1;Ft=si(Ut);var Ct=Ft,gt=N;if(0<Ut){Ut=Ct+Ut-1;for(var pn=0;pn<ct.length;++pn){var kt=ct.charCodeAt(pn);if(55296<=kt&&57343>=kt){var ur=ct.charCodeAt(++pn);kt=65536+((kt&1023)<<10)|ur&1023}if(127>=kt){if(Ct>=Ut)break;gt[Ct++]=kt}else{if(2047>=kt){if(Ct+1>=Ut)break;gt[Ct++]=192|kt>>6}else{if(65535>=kt){if(Ct+2>=Ut)break;gt[Ct++]=224|kt>>12}else{if(Ct+3>=Ut)break;gt[Ct++]=240|kt>>18,gt[Ct++]=128|kt>>12&63}gt[Ct++]=128|kt>>6&63}gt[Ct++]=128|kt&63}}gt[Ct]=0}}return Ft},array:function(ct){var Ft=si(ct.length);return k.set(ct,Ft),Ft}},Lt=F(J),Cn=[];if(J=0,Oe)for(var ln=0;ln<Oe.length;ln++){var kr=Je[we[ln]];kr?(J===0&&(J=ii()),Cn[ln]=kr(Oe[ln])):Cn[ln]=Oe[ln]}return we=Lt.apply(null,Cn),we=(function(ct){if(pe==="string")if(ct){for(var Ft=N,Ut=ct+NaN,Ct=ct;Ft[Ct]&&!(Ct>=Ut);)++Ct;if(16<Ct-ct&&Ft.subarray&&b)ct=b.decode(Ft.subarray(ct,Ct));else{for(Ut="";ct<Ct;){var gt=Ft[ct++];if(gt&128){var pn=Ft[ct++]&63;if((gt&224)==192)Ut+=String.fromCharCode((gt&31)<<6|pn);else{var kt=Ft[ct++]&63;gt=(gt&240)==224?(gt&15)<<12|pn<<6|kt:(gt&7)<<18|pn<<12|kt<<6|Ft[ct++]&63,65536>gt?Ut+=String.fromCharCode(gt):(gt-=65536,Ut+=String.fromCharCode(55296|gt>>10,56320|gt&1023))}}else Ut+=String.fromCharCode(gt)}ct=Ut}}else ct="";else ct=pe==="boolean"?!!ct:ct;return ct})(we),J!==0&&Gi(J),we}var b=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,w,k,N;function R(){var J=q.buffer;w=J,e.HEAP8=k=new Int8Array(J),e.HEAP16=new Int16Array(J),e.HEAP32=new Int32Array(J),e.HEAPU8=N=new Uint8Array(J),e.HEAPU16=new Uint16Array(J),e.HEAPU32=new Uint32Array(J),e.HEAPF32=new Float32Array(J),e.HEAPF64=new Float64Array(J)}var ie,j=[],X=[],re=[];function fe(){var J=e.preRun.shift();j.unshift(J)}var H=0,B=null,L=null;e.preloadedImages={},e.preloadedAudios={};function z(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."),i(J),J}var ne="data:application/octet-stream;base64,",de;if(de="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==",!de.startsWith(ne)){var oe=de;de=e.locateFile?e.locateFile(oe,u):u+oe}function Xe(){var J=de;try{if(J==de&&x)return new Uint8Array(x);var pe=On(J);if(pe)return pe;if(p)return p(J);throw"both async and sync fetching of the wasm failed"}catch(we){z(we)}}function dt(){if(!x&&(a||c)){if(typeof fetch=="function"&&!de.startsWith("file://"))return fetch(de,{credentials:"same-origin"}).then(function(J){if(!J.ok)throw"failed to load wasm binary file at '"+de+"'";return J.arrayBuffer()}).catch(function(){return Xe()});if(h)return new Promise(function(J,pe){h(de,function(we){J(new Uint8Array(we))},pe)})}return Promise.resolve().then(function(){return Xe()})}function cn(J){for(;0<J.length;){var pe=J.shift();if(typeof pe=="function")pe(e);else{var we=pe.m;typeof we=="number"?pe.l===void 0?ie.get(we)():ie.get(we)(pe.l):we(pe.l===void 0?null:pe.l)}}}var Sr=!1,xr=typeof atob=="function"?atob:function(J){var pe="",we=0;J=J.replace(/[^A-Za-z0-9\+\/=]/g,"");do{var Oe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(J.charAt(we++)),Je="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(J.charAt(we++)),Lt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(J.charAt(we++)),Cn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(J.charAt(we++));Oe=Oe<<2|Je>>4,Je=(Je&15)<<4|Lt>>2;var ln=(Lt&3)<<6|Cn;pe+=String.fromCharCode(Oe),Lt!==64&&(pe+=String.fromCharCode(Je)),Cn!==64&&(pe+=String.fromCharCode(ln))}while(we<J.length);return pe};function On(J){if(J.startsWith(ne)){if(J=J.slice(ne.length),typeof l=="boolean"&&l){var pe=Buffer.from(J,"base64");pe=new Uint8Array(pe.buffer,pe.byteOffset,pe.byteLength)}else try{var we=xr(J),Oe=new Uint8Array(we.length);for(J=0;J<we.length;++J)Oe[J]=we.charCodeAt(J);pe=Oe}catch{throw Error("Converting base64 string to bytes failed.")}return pe}}var wr={a:function(J){var pe=N.length;if(J>>>=0,2147483648<J)return!1;for(var we=1;4>=we;we*=2){var Oe=pe*(1+.2/we);Oe=Math.min(Oe,J+100663296),Oe=Math.max(J,Oe),0<Oe%65536&&(Oe+=65536-Oe%65536);e:{try{q.grow(Math.min(2147483648,Oe)-w.byteLength+65535>>>16),R();var Je=1;break e}catch{}Je=void 0}if(Je)return!0}return!1}};(function(){function J(Je){e.asm=Je.exports,q=e.asm.b,R(),ie=e.asm.j,X.unshift(e.asm.c),H--,e.monitorRunDependencies&&e.monitorRunDependencies(H),H==0&&(B!==null&&(clearInterval(B),B=null),L&&(Je=L,L=null,Je()))}function pe(Je){J(Je.instance)}function we(Je){return dt().then(function(Lt){return WebAssembly.instantiate(Lt,Oe)}).then(Je,function(Lt){S("failed to asynchronously prepare wasm: "+Lt),z(Lt)})}var Oe={a:wr};if(H++,e.monitorRunDependencies&&e.monitorRunDependencies(H),e.instantiateWasm)try{return e.instantiateWasm(Oe,J)}catch(Je){return S("Module.instantiateWasm callback failed with error: "+Je),!1}return(function(){return x||typeof WebAssembly.instantiateStreaming!="function"||de.startsWith(ne)||de.startsWith("file://")||typeof fetch!="function"?we(pe):fetch(de,{credentials:"same-origin"}).then(function(Je){return WebAssembly.instantiateStreaming(Je,Oe).then(pe,function(Lt){return S("wasm streaming compile failed: "+Lt),S("falling back to ArrayBuffer instantiation"),we(pe)})})})().catch(i),{}})(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.c).apply(null,arguments)},e._poly1305_auth=function(){return(e._poly1305_auth=e.asm.d).apply(null,arguments)};var ii=e.stackSave=function(){return(ii=e.stackSave=e.asm.e).apply(null,arguments)},Gi=e.stackRestore=function(){return(Gi=e.stackRestore=e.asm.f).apply(null,arguments)},si=e.stackAlloc=function(){return(si=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,pe,we,Oe){we=we||[];var Je=we.every(function(Lt){return Lt==="number"});return pe!=="string"&&Je&&!Oe?F(J):function(){return v(J,pe,we,arguments)}};var Ir;L=function J(){Ir||Cr(),Ir||(L=J)};function Cr(){function J(){if(!Ir&&(Ir=!0,e.calledRun=!0,!C)){if(cn(X),r(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;){var pe=e.postRun.shift();re.unshift(pe)}cn(re)}}if(!(0<H)){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)fe();cn(j),0<H||(e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),J()},1)):J())}}if(e.run=Cr,e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);0<e.preInit.length;)e.preInit.pop()();return Cr(),t.ready})})();typeof fs=="object"&&typeof Bo=="object"?Bo.exports=No:typeof define=="function"&&define.amd?define([],function(){return No}):typeof fs=="object"&&(fs.createPoly1305=No)});var Gn=lt((oE,pl)=>{"use strict";var{createCipheriv:Lr,createDecipheriv:ds,createHmac:Ro,randomFillSync:pr,timingSafeEqual:Po}=require("crypto"),{readUInt32BE:pi,writeUInt32BE:fn}=En(),Yn=Buffer[Symbol.species],ul=2**32-1,fl=Buffer.alloc(0),Mr=Buffer.alloc(4),hs=new Map,mr=35e3,To,Go,Yo,jo,Xo,Jo,Zo;try{To=require("./crypto/build/Release/sshcrypto.node"),{AESGCMCipher:Go,ChaChaPolyCipher:Yo,GenericCipher:jo,AESGCMDecipher:Xo,ChaChaPolyDecipher:Jo,GenericDecipher:Zo}=To}catch{}var qt=1,Lp=(()=>{function n(t,e,r,i,s,o,a){return{sslName:t,blockLen:e,keyLen:r,ivLen:i!==0||a&qt?i:e,authLen:s,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)}})(),Dp=(()=>{function n(t,e,r,i){return{sslName:t,len:e,actualLen:r,isETM:i}}return{"hmac-md5":n("md5",16,16,!1),"hmac-md5-96":n("md5",16,12,!1),"hmac-ripemd160":n("ripemd160",20,20,!1),"hmac-sha1":n("sha1",20,20,!1),"hmac-sha1-etm@openssh.com":n("sha1",20,20,!0),"hmac-sha1-96":n("sha1",20,12,!1),"hmac-sha2-256":n("sha256",32,32,!1),"hmac-sha2-256-etm@openssh.com":n("sha256",32,32,!0),"hmac-sha2-256-96":n("sha256",32,12,!1),"hmac-sha2-512":n("sha512",64,64,!1),"hmac-sha2-512-etm@openssh.com":n("sha512",64,64,!0),"hmac-sha2-512-96":n("sha512",64,12,!1)}})(),Oo=class{constructor(t,e){this.outSeqno=t,this._onWrite=e,this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,r=8-(e&7);r<4&&(r+=8),e+=r;let i=Buffer.allocUnsafe(e);return fn(i,e-4,0),i[4]=r,pr(i,5+t,r),i}encrypt(t){this._dead||(this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},dl=Buffer.alloc(32),nn=Buffer.alloc(16),hi,mi,ea,Mo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encKeyMain=e.cipherKey.slice(0,32),this._encKeyPktLen=e.cipherKey.slice(32),this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,r=8-(e-4&7);r<4&&(r+=8),e+=r;let i=Buffer.allocUnsafe(e);return fn(i,e-4,0),i[4]=r,pr(i,5+t,r),i}encrypt(t){if(this._dead)return;nn[0]=0,fn(nn,this.outSeqno,12);let e=Lr("chacha20",this._encKeyMain,nn).update(dl),r=Lr("chacha20",this._encKeyPktLen,nn).update(t.slice(0,4));this._onWrite(r),nn[0]=1;let i=Lr("chacha20",this._encKeyMain,nn).update(t.slice(4));this._onWrite(i),ea(mi,r,r.length,i,i.length,e);let s=Buffer.allocUnsafe(16);s.set(new Uint8Array(hi.HEAPU8.buffer,mi,16),0),this._onWrite(s),this.outSeqno=this.outSeqno+1>>>0}},Lo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new Yo(e.cipherKey),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=5+t,r=8-(e-4&7);r<4&&(r+=8),e+=r;let i=Buffer.allocUnsafe(e+16);return fn(i,e-4,0),i[4]=r,pr(i,5+t,r),i}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Do=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encSSLName=e.cipherInfo.sslName,this._encKey=e.cipherKey,this._encIV=e.cipherIV,this._dead=!1}free(){this._dead=!0}allocPacket(t){let e=5+t,r=16-(e-4&15);r<4&&(r+=16),e+=r;let i=Buffer.allocUnsafe(e);return fn(i,e-4,0),i[4]=r,pr(i,5+t,r),i}encrypt(t){if(this._dead)return;let e=Lr(this._encSSLName,this._encKey,this._encIV);e.setAutoPadding(!1);let r=t.slice(0,4);e.setAAD(r),this._onWrite(r);let i=e.update(t.slice(4));this._onWrite(i);let s=e.final();s.length&&this._onWrite(s);let o=e.getAuthTag();this._onWrite(o),hl(this._encIV),this.outSeqno=this.outSeqno+1>>>0}},Uo=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._instance=new Go(e.cipherInfo.sslName,e.cipherKey,e.cipherIV),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=5+t,r=16-(e-4&15);r<4&&(r+=16),e+=r;let i=Buffer.allocUnsafe(e+16);return fn(i,e-4,0),i[4]=r,pr(i,5+t,r),i}encrypt(t){this._dead||(this._instance.encrypt(t),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},$o=class{constructor(t){let e=t.outbound;this.outSeqno=e.seqno,this._onWrite=e.onWrite,this._encBlockLen=e.cipherInfo.blockLen,this._cipherInstance=Lr(e.cipherInfo.sslName,e.cipherKey,e.cipherIV),this._macSSLName=e.macInfo.sslName,this._macKey=e.macKey,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM,this._aadLen=this._macETM?4:0,this._dead=!1;let r=e.cipherInfo.discardLen;if(r){let i=hs.get(r);i===void 0&&(i=Buffer.alloc(r),hs.set(r,i)),this._cipherInstance.update(i)}}free(){this._dead=!0}allocPacket(t){let e=this._encBlockLen,r=5+t,i=e-(r-this._aadLen&e-1);i<4&&(i+=e),r+=i;let s=Buffer.allocUnsafe(r);return fn(s,r-4,0),s[4]=i,pr(s,5+t,i),s}encrypt(t){if(this._dead)return;let e;if(this._macETM){let i=new Uint8Array(t.buffer,t.byteOffset,4),s=this._cipherInstance.update(new Uint8Array(t.buffer,t.byteOffset+4,t.length-4));this._onWrite(i),this._onWrite(s),e=Ro(this._macSSLName,this._macKey),fn(Mr,this.outSeqno,0),e.update(Mr),e.update(i),e.update(s)}else{let i=this._cipherInstance.update(t);this._onWrite(i),e=Ro(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}},Fo=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 jo(e.cipherInfo.sslName,e.cipherKey,e.cipherIV,e.macInfo.sslName,e.macKey,e.macInfo.isETM),this._dead=!1}free(){this._dead=!0,this._instance.free()}allocPacket(t){let e=this._encBlockLen,r=5+t,i=e-(r-this._aadLen&e-1);i<4&&(i+=e),r+=i;let s=Buffer.allocUnsafe(r+this._macLen);return fn(s,r-4,0),s[4]=i,pr(s,5+t,i),s}encrypt(t){this._dead||(this._instance.encrypt(t,this.outSeqno),this._macActualLen<this._macLen&&(t=new Yn(t.buffer,t.byteOffset,t.length-(this._macLen-this._macActualLen))),this._onWrite(t),this.outSeqno=this.outSeqno+1>>>0)}},Ho=class{constructor(t,e){this.inSeqno=t,this._onPayload=e,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenBytes<4){let s=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=s;s--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len>mr||this._len<8||(4+this._len&7)!==0)throw new Error("Bad packet length");if(e>=r)return}if(this._packetPos<this._len){let s=Math.min(this._len-this._packetPos,r-e),o;if(e!==0||s!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,s):o=t,s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._packetPos)),e+=s,this._packetPos+=s,this._packetPos<this._len)return}let i=this._packet?new Yn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):fl;this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}},Qo=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;nn[0]=0,fn(nn,this.inSeqno,12);let c=ds("chacha20",this._decKeyPktLen,nn).update(this._lenBuf);if(this._len=pi(c,0),this._len>mr||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}nn[0]=0,fn(nn,this.inSeqno,12);let i=Lr("chacha20",this._decKeyMain,nn).update(dl);if(ea(mi,this._lenBuf,4,this._packet,this._packet.length,i),this._calcMac.set(new Uint8Array(hi.HEAPU8.buffer,mi,16),0),!Po(this._calcMac,this._mac))throw new Error("Invalid MAC");nn[0]=1;let s=ds("chacha20",this._decKeyMain,nn).update(this._packet),o=new Yn(s.buffer,s.byteOffset+1,s.length-s[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenPos=0,this._packet=null,this._pktLen=0,this._macPos=0;{let a=this._onPayload(o);if(a!==void 0)return a===!1?e:a}}}},Wo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new Jo(e.decipherKey),this._len=0,this._lenBuf=Buffer.alloc(4),this._lenPos=0,this._packet=null,this._pktLen=0,this._mac=Buffer.allocUnsafe(16),this._macPos=0}free(){this._instance.free()}decrypt(t,e,r){for(;e<r;){if(this._lenPos<4){let s=Math.min(4-this._lenPos,r-e);for(;s--;)this._lenBuf[this._lenPos++]=t[e++];if(this._lenPos<4)return;if(this._len=this._instance.decryptLen(this._lenBuf,this.inSeqno),this._len>mr||this._len<8||(this._len&7)!==0)throw new Error("Bad packet length");if(e>=r)return}if(this._pktLen<this._len){let s=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||s!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,s):o=t,s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=s,this._pktLen+=s,this._pktLen<this._len||e>=r)return}{let s=Math.min(16-this._macPos,r-e);if(e!==0||s!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._macPos):this._mac.set(t,this._macPos),e+=s,this._macPos+=s,this._macPos<16)return}this._instance.decrypt(this._packet,this._mac,this.inSeqno);let i=new Yn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenPos=0,this._packet=null,this._pktLen=0,this._macPos=0;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}},qo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decipherInstance=null,this._decipherSSLName=e.decipherInfo.sslName,this._decipherKey=e.decipherKey,this._decipherIV=e.decipherIV,this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._tag=Buffer.allocUnsafe(16),this._tagPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenBytes<4){let s=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=s;s--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len+20>mr||this._len<16||(this._len&15)!==0)throw new Error("Bad packet length");this._decipherInstance=ds(this._decipherSSLName,this._decipherKey,this._decipherIV),this._decipherInstance.setAutoPadding(!1),this._decipherInstance.setAAD(Up(this._len))}if(this._pktLen<this._len){if(e>=r)return;let s=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||s!==r?o=this._decipherInstance.update(new Uint8Array(t.buffer,t.byteOffset+e,s)):o=this._decipherInstance.update(t),o.length&&(s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._packetPos)),this._packetPos+=o.length),e+=s,this._pktLen+=s,this._pktLen<this._len||e>=r)return}{let s=Math.min(16-this._tagPos,r-e);if(e!==0||s!==r?this._tag.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._tagPos):this._tag.set(t,this._tagPos),e+=s,this._tagPos+=s,this._tagPos<16)return}{this._decipherInstance.setAuthTag(this._tag);let s=this._decipherInstance.final();s.length&&(this._packet?this._packet.set(s,this._packetPos):this._packet=s)}let i=this._packet?new Yn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1):fl;this.inSeqno=this.inSeqno+1>>>0,hl(this._decipherIV),this._len=0,this._lenBytes=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._tagPos=0;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}},Ko=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new Xo(e.decipherInfo.sslName,e.decipherKey,e.decipherIV),this._len=0,this._lenBytes=0,this._packet=null,this._pktLen=0,this._tag=Buffer.allocUnsafe(16),this._tagPos=0}free(){}decrypt(t,e,r){for(;e<r;){if(this._lenBytes<4){let s=Math.min(4-this._lenBytes,r-e);for(this._lenBytes+=s;s--;)this._len=(this._len<<8)+t[e++];if(this._lenBytes<4)return;if(this._len+20>mr||this._len<16||(this._len&15)!==0)throw new Error(`Bad packet length: ${this._len}`)}if(this._pktLen<this._len){if(e>=r)return;let s=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||s!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,s):o=t,s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=s,this._pktLen+=s,this._pktLen<this._len||e>=r)return}{let s=Math.min(16-this._tagPos,r-e);if(e!==0||s!==r?this._tag.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._tagPos):this._tag.set(t,this._tagPos),e+=s,this._tagPos+=s,this._tagPos<16)return}this._instance.decrypt(this._packet,this._len,this._tag);let i=new Yn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._len=0,this._lenBytes=0,this._packet=null,this._pktLen=0,this._tagPos=0;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}},Vo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._decipherInstance=ds(e.decipherInfo.sslName,e.decipherKey,e.decipherIV),this._decipherInstance.setAutoPadding(!1),this._block=Buffer.allocUnsafe(e.macInfo.isETM?4:e.decipherInfo.blockLen),this._blockSize=e.decipherInfo.blockLen,this._blockPos=0,this._len=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._mac=Buffer.allocUnsafe(e.macInfo.actualLen),this._macPos=0,this._macSSLName=e.macInfo.sslName,this._macKey=e.macKey,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM,this._macInstance=null;let r=e.decipherInfo.discardLen;if(r){let i=hs.get(r);i===void 0&&(i=Buffer.alloc(r),hs.set(r,i)),this._decipherInstance.update(i)}}free(){}decrypt(t,e,r){for(;e<r;){if(this._blockPos<this._block.length){let o=Math.min(this._block.length-this._blockPos,r-e);if(e!==0||o!==r||o<t.length?this._block.set(new Uint8Array(t.buffer,t.byteOffset+e,o),this._blockPos):this._block.set(t,this._blockPos),e+=o,this._blockPos+=o,this._blockPos<this._block.length)return;let a,c;if(this._macETM?this._len=c=pi(this._block,0):(a=this._decipherInstance.update(this._block),this._len=pi(a,0),c=4+this._len-this._blockSize),this._len>mr||this._len<5||(c&this._blockSize-1)!==0)throw new Error("Bad packet length");if(this._macInstance=Ro(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 i=this._macInstance.digest();if(this._macActualLen<i.length&&(i=new Uint8Array(i.buffer,i.byteOffset,this._macActualLen)),!$p(i,this._mac))throw new Error("Invalid MAC");let s=new Yn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._blockPos=0,this._len=0,this._packet=null,this._packetPos=0,this._pktLen=0,this._macPos=0,this._macInstance=null;{let o=this._onPayload(s);if(o!==void 0)return o===!1?e:o}}}},zo=class{constructor(t){let e=t.inbound;this.inSeqno=e.seqno,this._onPayload=e.onPayload,this._instance=new Zo(e.decipherInfo.sslName,e.decipherKey,e.decipherIV,e.macInfo.sslName,e.macKey,e.macInfo.isETM,e.macInfo.actualLen),this._block=Buffer.allocUnsafe(e.macInfo.isETM||e.decipherInfo.stream?4:e.decipherInfo.blockLen),this._blockPos=0,this._len=0,this._packet=null,this._pktLen=0,this._mac=Buffer.allocUnsafe(e.macInfo.actualLen),this._macPos=0,this._macActualLen=e.macInfo.actualLen,this._macETM=e.macInfo.isETM}free(){this._instance.free()}decrypt(t,e,r){for(;e<r;){if(this._blockPos<this._block.length){let s=Math.min(this._block.length-this._blockPos,r-e);if(e!==0||s!==r||s<t.length?this._block.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._blockPos):this._block.set(t,this._blockPos),e+=s,this._blockPos+=s,this._blockPos<this._block.length)return;let o;if(this._macETM?this._len=o=pi(this._block,0):(this._instance.decryptBlock(this._block),this._len=pi(this._block,0),o=4+this._len-this._block.length),this._len>mr||this._len<5||(o&this._block.length-1)!==0)throw new Error("Bad packet length");if(this._macETM||(this._pktLen=this._block.length-4,this._pktLen&&(this._packet=Buffer.allocUnsafe(this._len),this._packet.set(new Uint8Array(this._block.buffer,this._block.byteOffset+4,this._pktLen),0))),e>=r)return}if(this._pktLen<this._len){let s=Math.min(this._len-this._pktLen,r-e),o;if(e!==0||s!==r?o=new Uint8Array(t.buffer,t.byteOffset+e,s):o=t,s===this._len?this._packet=o:(this._packet||(this._packet=Buffer.allocUnsafe(this._len)),this._packet.set(o,this._pktLen)),e+=s,this._pktLen+=s,this._pktLen<this._len||e>=r)return}{let s=Math.min(this._macActualLen-this._macPos,r-e);if(e!==0||s!==r?this._mac.set(new Uint8Array(t.buffer,t.byteOffset+e,s),this._macPos):this._mac.set(t,this._macPos),e+=s,this._macPos+=s,this._macPos<this._macActualLen)return}this._instance.decrypt(this._packet,this.inSeqno,this._block,this._mac);let i=new Yn(this._packet.buffer,this._packet.byteOffset+1,this._packet.length-this._packet[0]-1);this.inSeqno=this.inSeqno+1>>>0,this._blockPos=0,this._len=0,this._packet=null,this._pktLen=0,this._macPos=0,this._macInstance=null;{let s=this._onPayload(i);if(s!==void 0)return s===!1?e:s}}}};function hl(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 Up=(()=>{let n=Buffer.alloc(4);return t=>(n[0]=t>>>24,n[1]=t>>>16,n[2]=t>>>8,n[3]=t,n)})();function $p(n,t){return n.length!==t.length?(Po(n,n),!1):Po(n,t)}function Fp(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>ul)throw new Error("Invalid outbound.seqno");let e=!!t.forceNative;switch(t.cipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return Go&&!e?new Uo(n):new Do(n);case"chacha20":return Yo&&!e?new Lo(n):new Mo(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 jo&&!e?new Fo(n):new $o(n)}}}function Hp(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>ul)throw new Error("Invalid inbound.seqno");let e=!!t.forceNative;switch(t.decipherInfo.sslName){case"aes-128-gcm":case"aes-256-gcm":return Xo&&!e?new Ko(n):new qo(n);case"chacha20":return Jo&&!e?new Wo(n):new Qo(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 Zo&&!e?new zo(n):new Vo(n)}}}pl.exports={CIPHER_INFO:Lp,MAC_INFO:Dp,bindingAvailable:!!To,init:new Promise(async(n,t)=>{try{hi=await ll()(),mi=hi._malloc(16),ea=hi.cwrap("poly1305_auth",null,["number","array","number","array","number","array"])}catch(e){return t(e)}n()}),NullCipher:Oo,createCipher:Fp,NullDecipher:Ho,createDecipher:Hp}});var Xn=lt((aE,wl)=>{"use strict";var{createDecipheriv:na,createECDH:Qp,createHash:Ai,createHmac:Wp,createSign:qp,createVerify:Kp,getCiphers:Vp,sign:ml,verify:gl}=require("crypto"),zp=Vp(),{Ber:Re}=ui(),Gp=Io().pbkdf,{CIPHER_INFO:yi}=Gn(),{eddsaSupported:ra,SUPPORTED_CIPHER:Yp}=Un(),{bufferSlice:gr,makeBufferParser:jp,readString:Ne,readUInt32BE:gi,writeUInt32BE:Ht}=En(),$n=Symbol("Hash Algorithm"),_n=Symbol("Private key PEM"),kn=Symbol("Public key PEM"),jn=Symbol("Public key SSH"),Dr=Symbol("Decrypted Key"),ta=Object.create(null);{let n=Object.keys(yi);for(let t=0;t<n.length;++t){let e=yi[n[t]].sslName;!e||ta[e]||(ta[e]=yi[n[t]])}}var ps=jp();function bn(n,t){t=t.base64Slice(0,t.length);let e=t.replace(/.{64}/g,`$&
5
5
  `);return t.length&63&&(e+=`
6
6
  `),`-----BEGIN ${n} KEY-----
7
- ${e}-----END ${n} KEY-----`}function yi(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return e.set(n,0),e.set(t,n.length),e}function na(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=mi(n,r);if(i<4+o)return!1;r+=4+o}return n._pos=r,!0}function Ei(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(),bn("PUBLIC",e.buffer)}function _i(n,t){let e=Buffer.allocUnsafe(15+t.length+4+n.length);Ht(e,7,0),e.utf8Write("ssh-rsa",4,7);let r=11;return Ht(e,t.length,r),e.set(t,r+=4),Ht(e,n.length,r+=t.length),e.set(n,r+4),e}var ml=(()=>{function n(r,s,i,o,a,c,l,u){let f=new Re.Writer;return f.startSequence(),f.writeInt(0,Re.Integer),f.writeBuffer(r,Re.Integer),f.writeBuffer(s,Re.Integer),f.writeBuffer(i,Re.Integer),f.writeBuffer(o,Re.Integer),f.writeBuffer(a,Re.Integer),f.writeBuffer(c,Re.Integer),f.writeBuffer(l,Re.Integer),f.writeBuffer(u,Re.Integer),f.endSequence(),f.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 u=t(o),f=e(u%(t(c)-1n)),h=e(u%(t(l)-1n));return bn("RSA PRIVATE",n(s,i,o,c,l,f,h,a))}})();function bi(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(),bn("PUBLIC",s.buffer)}function Si(n,t,e,r){let s=Buffer.allocUnsafe(15+n.length+4+t.length+4+e.length+4+r.length);Ht(s,7,0),s.utf8Write("ssh-dss",4,7);let i=11;return Ht(s,n.length,i),s.set(n,i+=4),Ht(s,t.length,i+=n.length),s.set(t,i+=4),Ht(s,e.length,i+=t.length),s.set(e,i+=4),Ht(s,r.length,i+=e.length),s.set(r,i+4),s}function gl(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(),bn("DSA PRIVATE",i.buffer)}function Al(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(),bn("PUBLIC",t.buffer)}function yl(n){let t=Buffer.allocUnsafe(19+n.length);return Ht(t,11,0),t.utf8Write("ssh-ed25519",4,11),Ht(t,n.length,15),t.set(n,19),t}function Yp(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(),bn("PRIVATE",t.buffer)}function ra(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(),bn("PUBLIC",e.buffer)}function ia(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 Ht(r,19,0),r.utf8Write(`ecdsa-sha2-${e}`,4,19),Ht(r,8,23),r.utf8Write(e,27,8),Ht(r,t.length,35),r.set(t,39),r}function jp(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(),bn("EC PRIVATE",r.buffer)}function Xp(n,t){let e=Fp(n);return e.setPrivateKey(t),e.getPublicKey()}var xi={sign:typeof hl=="function"?function(t,e){let r=this[_n];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[$n]);try{return hl(e,t,r)}catch(s){return s}}:function(t,e){let r=this[_n];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[$n]);let s=Qp(e);s.update(t);try{return s.sign(r)}catch(i){return i}},verify:typeof pl=="function"?function(t,e,r){let s=this[kn];if(s===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[$n]);try{return pl(r,t,s,e)}catch(i){return i}}:function(t,e,r){let s=this[kn];if(s===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[$n]);let i=Wp(r);i.update(t);try{return i.verify(s,e)}catch(o){return o}},isPrivateKey:function(){return this[_n]!==null},getPrivatePEM:function(){return this[_n]},getPublicPEM:function(){return this[kn]},getPublicSSH:function(){return this[jn]},equals:function(t){let e=bl(t);return e instanceof Error?!1:this.type===e.type&&this[_n]===e[_n]&&this[kn]===e[kn]&&this[jn].equals(e[jn])}};function ps(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[_n]=e,this[kn]=r,this[jn]=s,this[$n]=i,this[Lr]=o}ps.prototype=xi;{let t=function(e,r,s){let i=[];if(e.length<8)return new Error("Malformed OpenSSH private key");let o=mi(e,0),a=mi(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 f,h,p,y,E=Ne(e,e._pos,!0);if(E===void 0)return new Error("Malformed OpenSSH private key");switch(E){case"ssh-rsa":{let x=Ne(e,e._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");let P=Ne(e,e._pos);if(P===void 0)return new Error("Malformed OpenSSH private key");let q=Ne(e,e._pos);if(q===void 0)return new Error("Malformed OpenSSH private key");let C=Ne(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let $=Ne(e,e._pos);if($===void 0)return new Error("Malformed OpenSSH private key");let F=Ne(e,e._pos);if(F===void 0)return new Error("Malformed OpenSSH private key");p=Ei(x,P),y=_i(x,P),h=ml(x,P,q,C,$,F),f="sha1";break}case"ssh-dss":{let x=Ne(e,e._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");let P=Ne(e,e._pos);if(P===void 0)return new Error("Malformed OpenSSH private key");let q=Ne(e,e._pos);if(q===void 0)return new Error("Malformed OpenSSH private key");let C=Ne(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let $=Ne(e,e._pos);if($===void 0)return new Error("Malformed OpenSSH private key");p=bi(x,P,q,C),y=Si(x,P,q,C),h=gl(x,P,q,C,$),f="sha1";break}case"ssh-ed25519":{if(!ta)return new Error(`Unsupported OpenSSH private key type: ${E}`);let x=Ne(e,e._pos);if(x===void 0||x.length!==32)return new Error("Malformed OpenSSH private key");let P=Ne(e,e._pos);if(P===void 0||P.length!==64)return new Error("Malformed OpenSSH private key");p=Al(x),y=yl(x),h=Yp(mr(P,0,32)),f=null;break}case"ecdsa-sha2-nistp256":f="sha256",l="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":f===void 0&&(f="sha384",l="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(f===void 0&&(f="sha512",l="1.3.132.0.35"),!na(e,1))return new Error("Malformed OpenSSH private key");let x=Ne(e,e._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");let P=Ne(e,e._pos);if(P===void 0)return new Error("Malformed OpenSSH private key");p=ra(l,x),y=ia(l,x),h=jp(l,x,P);break}default:return new Error(`Unsupported OpenSSH private key type: ${E}`)}let S=Ne(e,e._pos,!0);if(S===void 0)return new Error("Malformed OpenSSH private key");i.push(new ps(E,S,h,p,y,f,s))}let u=0;for(c=e._pos;c<e.length;++c)if(e[c]!==++u%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-----$/;ps.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=Ne(o,15,!0);if(c===void 0)return new Error("Malformed OpenSSH private key");if(c!=="none"&&zp.indexOf(c)===-1)return new Error(`Unsupported cipher for OpenSSH key: ${c}`);let l=Ne(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 u,f,h;c!=="none"&&(u=Ai[c]);let p=Ne(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=Ne(p,0);if(E===void 0||p._pos+4>p.length)return new Error("Malformed OpenSSH private key");let S=mi(p,p._pos),x=Buffer.allocUnsafe(u.keyLen+u.ivLen);if(Vp(r,r.length,E,E.length,x,x.length,S)!==0)return new Error("Failed to generate information to decrypt key");f=mr(x,0,u.keyLen),h=mr(x,u.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 y=mi(o,o._pos);if(o._pos+=4,y>0){for(let S=0;S<y;++S){let x=Ne(o,o._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");if(Ne(x,0,!0)===void 0)return new Error("Malformed OpenSSH private key")}let E=Ne(o,o._pos);if(E===void 0)return new Error("Malformed OpenSSH private key");if(f!==void 0){if(E.length<u.blockLen||E.length%u.blockLen!==0)return new Error("Malformed OpenSSH private key");try{let S={authTagLength:u.authLen},x=ea(u.sslName,f,h,S);if(x.setAutoPadding(!1),u.authLen>0){if(o.length-o._pos<u.authLen)return new Error("Malformed OpenSSH private key");x.setAuthTag(mr(o,o._pos,o._pos+=u.authLen))}E=yi(x.update(E),x.final())}catch(S){return S}}if(o._pos!==o.length)return new Error("Malformed OpenSSH private key");i=t(E,y,f!==void 0)}else i=[];return i instanceof Error?i:i[0]}}function ms(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[_n]=e,this[kn]=r,this[jn]=s,this[$n]=i,this[Lr]=o}ms.prototype=xi;{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-----$/;ms.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 y=0;y<i.length;++y){let E=i[y],S=E.indexOf(":");if(E.slice(0,S)==="DEK-Info"){let x=E.slice(S+2);if(S=x.indexOf(","),S===-1)continue;let P=x.slice(0,S).toLowerCase();if(Kp.indexOf(P)===-1)return new Error(`Cipher (${P}) not supported for encrypted OpenSSH private key`);let q=Zo[P];if(!q)return new Error(`Cipher (${P}) not supported for encrypted OpenSSH private key`);let C=Buffer.from(x.slice(S+1),"hex");if(C.length!==q.ivLen)return new Error("Malformed encrypted OpenSSH private key");if(!e)return new Error("Encrypted OpenSSH private key detected, but no passphrase given");let $=mr(C,0,8),F=gi("md5").update(e).update($).digest();for(;F.length<q.keyLen;)F=yi(F,gi("md5").update(F).update(e).update($).digest());F.length>q.keyLen&&(F=mr(F,0,q.keyLen));try{let v=ea(P,F,C);v.setAutoPadding(!1),s=yi(v.update(s),v.final()),o=!0}catch(v){return v}}}}let a,c,l,u,f,h,p="Malformed OpenSSH private key";switch(o&&(p+=". Bad passphrase?"),r[1]){case"RSA":a="ssh-rsa",c=bn("RSA PRIVATE",s);try{h=new Re.Reader(s),h.readSequence(),h.readInt();let y=h.readString(Re.Integer,!0);if(y===null)return new Error(p);let E=h.readString(Re.Integer,!0);if(E===null)return new Error(p);l=Ei(y,E),u=_i(y,E)}catch{return new Error(p)}f="sha1";break;case"DSA":a="ssh-dss",c=bn("DSA PRIVATE",s);try{h=new Re.Reader(s),h.readSequence(),h.readInt();let y=h.readString(Re.Integer,!0);if(y===null)return new Error(p);let E=h.readString(Re.Integer,!0);if(E===null)return new Error(p);let S=h.readString(Re.Integer,!0);if(S===null)return new Error(p);let x=h.readString(Re.Integer,!0);if(x===null)return new Error(p);l=bi(y,E,S,x),u=Si(y,E,S,x)}catch{return new Error(p)}f="sha1";break;case"EC":{let y,E,S;try{h=new Re.Reader(s),h.readSequence(),h.readInt(),E=h.readString(Re.OctetString,!0),h.readByte();let P=h.readLength();if(P!==null){if(h._offset=P,S=h.readOID(),S===null)return new Error(p);switch(S){case"1.2.840.10045.3.1.7":y="prime256v1",a="ecdsa-sha2-nistp256",f="sha256";break;case"1.3.132.0.34":y="secp384r1",a="ecdsa-sha2-nistp384",f="sha384";break;case"1.3.132.0.35":y="secp521r1",a="ecdsa-sha2-nistp521",f="sha512";break;default:return new Error(`Unsupported private key EC OID: ${S}`)}}else return new Error(p)}catch{return new Error(p)}c=bn("EC PRIVATE",s);let x=Xp(y,E);l=ra(S,x),u=ia(S,x);break}}return new ms(a,"",c,l,u,f,o)}}function gs(n,t,e,r,s,i,o){this.type=n,this.comment=t,this[_n]=e,this[kn]=r,this[jn]=s,this[$n]=i,this[Lr]=o}gs.prototype=xi;{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]+)/;gs.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 u=Buffer.from(a[5],"base64");if(l){let k=Ai[c],N=yi(gi("sha1").update(e).update(o).digest(),gi("sha1").update(r).update(o).digest());N.length>k.keyLen&&(N=mr(N,0,k.keyLen));try{let R=ea(k.sslName,N,t);R.setAutoPadding(!1),u=yi(R.update(u),R.final())}catch(R){return R}}let f=a[1],h=a[3],p=Buffer.from(a[4],"base64"),y=a[6],E=f.length,S=c.length,x=Buffer.byteLength(h),P=p.length,q=u.length,C=Buffer.allocUnsafe(4+E+4+S+4+x+4+P+4+q),$=0;if(Ht(C,E,$),C.utf8Write(f,$+=4,E),Ht(C,S,$+=E),C.utf8Write(c,$+=4,S),Ht(C,x,$+=S),C.utf8Write(h,$+=4,x),Ht(C,P,$+=x),C.set(p,$+=4),Ht(C,q,$+=P),C.set(u,$+4),o||(o=n),Hp("sha1",gi("sha1").update("putty-private-key-file-mac-key").update(o).digest()).update(C).digest("hex")!==y)return l?new Error("PPK private key integrity check failed -- bad passphrase?"):new Error("PPK private key integrity check failed");let v,b,w;switch(p._pos=0,na(p,1),f){case"ssh-rsa":{let k=Ne(p,p._pos);if(k===void 0)return new Error("Malformed PPK public key");let N=Ne(p,p._pos);if(N===void 0)return new Error("Malformed PPK public key");let R=Ne(u,0);if(R===void 0)return new Error("Malformed PPK private key");let ie=Ne(u,u._pos);if(ie===void 0)return new Error("Malformed PPK private key");let j=Ne(u,u._pos);if(j===void 0)return new Error("Malformed PPK private key");let X=Ne(u,u._pos);if(X===void 0)return new Error("Malformed PPK private key");v=Ei(N,k),b=_i(N,k),w=ml(N,k,R,X,ie,j);break}case"ssh-dss":{let k=Ne(p,p._pos);if(k===void 0)return new Error("Malformed PPK public key");let N=Ne(p,p._pos);if(N===void 0)return new Error("Malformed PPK public key");let R=Ne(p,p._pos);if(R===void 0)return new Error("Malformed PPK public key");let ie=Ne(p,p._pos);if(ie===void 0)return new Error("Malformed PPK public key");let j=Ne(u,0);if(j===void 0)return new Error("Malformed PPK private key");v=bi(k,N,R,ie),b=Si(k,N,R,ie),w=gl(k,N,R,ie,j);break}}return new gs(f,h,w,v,b,"sha1",l)}}function ys(n,t,e,r,s){this.type=n,this.comment=t,this[_n]=null,this[kn]=e,this[jn]=r,this[$n]=s,this[Lr]=!1}ys.prototype=xi;{let n;ta?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].*)?)$/,ys.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=Ne(i,i._pos,!0);return a===void 0||a.indexOf(s)!==0?new Error("Malformed OpenSSH public key"):sa(i,s,o,r)}}function As(n,t,e,r,s){this.type=n,this.comment=t,this[_n]=null,this[kn]=e,this[jn]=r,this[$n]=s,this[Lr]=!1}As.prototype=xi;{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;As.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],y=i[2].replace(r,"");if(y.length>1024)return e.lastIndex=0,new Error("Malformed RFC4716 public key");a=e.lastIndex,p.toLowerCase()==="comment"&&(c=y,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 u=Ne(l,0,!0);if(u===void 0)return new Error("Malformed RFC4716 public key");let f=null,h=null;switch(u){case"ssh-rsa":{let p=Ne(l,l._pos);if(p===void 0)return new Error("Malformed RFC4716 public key");let y=Ne(l,l._pos);if(y===void 0)return new Error("Malformed RFC4716 public key");f=Ei(y,p),h=_i(y,p);break}case"ssh-dss":{let p=Ne(l,l._pos);if(p===void 0)return new Error("Malformed RFC4716 public key");let y=Ne(l,l._pos);if(y===void 0)return new Error("Malformed RFC4716 public key");let E=Ne(l,l._pos);if(E===void 0)return new Error("Malformed RFC4716 public key");let S=Ne(l,l._pos);if(S===void 0)return new Error("Malformed RFC4716 public key");f=bi(p,y,E,S),h=Si(p,y,E,S);break}default:return new Error("Malformed RFC4716 public key")}return new As(u,c,f,h,"sha1")}}function sa(n,t,e,r){if(!El(t))return new Error(`Unsupported OpenSSH public key type: ${t}`);let s,i,o=null,a=null;switch(t){case"ssh-rsa":{let c=Ne(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let l=Ne(n,n._pos);if(l===void 0)return new Error("Malformed OpenSSH public key");o=Ei(l,c),a=_i(l,c),s="sha1";break}case"ssh-dss":{let c=Ne(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let l=Ne(n,n._pos);if(l===void 0)return new Error("Malformed OpenSSH public key");let u=Ne(n,n._pos);if(u===void 0)return new Error("Malformed OpenSSH public key");let f=Ne(n,n._pos);if(f===void 0)return new Error("Malformed OpenSSH public key");o=bi(c,l,u,f),a=Si(c,l,u,f),s="sha1";break}case"ssh-ed25519":{let c=Ne(n,n._pos||0);if(c===void 0||c.length!==32)return new Error("Malformed OpenSSH public key");o=Al(c),a=yl(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"),!na(n,1))return new Error("Malformed OpenSSH public key");let c=Ne(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");o=ra(i,c),a=ia(i,c);break}default:return new Error(`Unsupported OpenSSH public key type: ${t}`)}return new ys(r,e,o,a,s)}function El(n){switch(n){case"ssh-rsa":case"ssh-dss":case"ecdsa-sha2-nistp256":case"ecdsa-sha2-nistp384":case"ecdsa-sha2-nistp521":return!0;case"ssh-ed25519":if(ta)return!0;default:return!1}}function _l(n){return n?typeof n[Lr]=="boolean":!1}function bl(n,t){if(_l(n))return n;let e;if(Buffer.isBuffer(n))e=n,n=n.utf8Slice(0,n.length).trim();else if(typeof n=="string")n=n.trim();else return new Error("Key data must be a Buffer or string");if(t!=null){if(typeof t=="string")t=Buffer.from(t);else if(!Buffer.isBuffer(t))return new Error("Passphrase must be a string or Buffer when supplied")}let r;if((r=ps.parse(n,t))!==null||(r=ms.parse(n,t))!==null||(r=gs.parse(n,t))!==null||(r=ys.parse(n))!==null||(r=As.parse(n))!==null)return r;if(e){hs.init(e,0);let s=hs.readString(!0);s!==void 0&&(n=hs.readRaw(),n!==void 0&&(r=sa(n,s,"",s),r instanceof Error&&(r=null))),hs.clear()}return r||new Error("Unsupported key format")}Sl.exports={isParsedKey:_l,isSupportedKeyType:El,parseDERKey:(n,t)=>sa(n,t,"",t),parseKey:bl}});var fa=lt((cE,Pl)=>{"use strict";var{Socket:Cl}=require("net"),{Duplex:kl}=require("stream"),{resolve:Jp}=require("path"),{readFile:xl}=require("fs"),{execFile:Zp,spawn:e0}=require("child_process"),{isParsedKey:wl,parseKey:wi}=Xn(),{makeBufferParser:t0,readUInt32BE:ua,writeUInt32BE:rn,writeUInt32LE:Il}=En();function Ii(n){let t=!1;return(...e)=>{t||(t=!0,n(...e))}}function n0(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return n.copy(e,0),t.copy(e,n.length),e}function aa(){}var r0=Buffer.alloc(0),xt=t0(),Ci=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"))}},Ur=class extends Ci{constructor(t){super(),this.socketPath=t}getStream(t){t=Ii(t);let e=new Cl;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=Ii(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 ca(!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=Ii(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 ca(!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,u)=>{if(l)return a(l);try{o.destroy()}catch{}s(null,u)})})}},vl=(()=>{let o=Jp(__dirname,"..","util/pagent.exe"),a={10:new Error("Invalid pagent.exe arguments"),11:new Error("Pageant is not running"),12:new Error("pagent.exe could not create an mmap"),13:new Error("pagent.exe could not set mode for stdin"),14:new Error("pagent.exe could not set mode for stdout"),15:new Error("pagent.exe did not get expected input payload")};function c(u){u.buffer=null,u.proc&&(u.proc.kill(),u.proc=void 0)}class l extends kl{constructor(){super(),this.proc=void 0,this.buffer=null}_read(f){}_write(f,h,p){if(this.buffer===null)this.buffer=f;else{let x=Buffer.allocUnsafe(this.buffer.length+f.length);this.buffer.copy(x,0),f.copy(x,this.buffer.length),this.buffer=x}if(this.buffer.length<4)return p();let y=ua(this.buffer,0);if(this.buffer.length-4<y)return p();if(f=this.buffer.slice(0,4+y),this.buffer.length>4+y)return p(new Error("Unexpected multiple agent requests"));this.buffer=null;let E,S=this.proc=e0(o,[f.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(f)}_final(f){c(this),f()}_destroy(f,h){c(this),h()}}return class extends Ur{getStream(f){f(null,new l)}}})(),Nl=(()=>{let n=/^!<socket >(\d+) s ([A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8})/;return class extends Ur{getStream(e){e=Ii(e);let r=this.socketPath,s=!1;xl(r,function i(o,a){if(o){if(s)return e(new Error("Invalid cygwin unix socket path"));Zp("cygpath",["-w",r],(F,v,b)=>{if(F||v.length===0)return e(new Error("Invalid cygwin unix socket path"));s=!0,r=v.toString().replace(/[\r\n]/g,""),xl(r,i)});return}let c=n.exec(a.toString("ascii"));if(!c)return e(new Error("Malformed cygwin unix socket file"));let l,u=0,f=!1,h=[],p,y=Buffer.alloc(12),E=parseInt(c[1],10),S=c[2].replace(/-/g,""),x=Buffer.allocUnsafe(16);for(let F=0,v=0;v<32;++F,v+=2)x[F]=parseInt(S.substring(v,v+2),16);for(let F=0;F<16;F+=4)Il(x,ua(x,F),F);$();function P(){u=0,l="secret",p.write(x)}function q(F){if(u+=F.length,l==="secret"){u===16&&(u=0,l="creds",p.write(y));return}if(l==="creds"&&(f||h.push(F),u===12)){if(p.removeListener("connect",P),p.removeListener("data",q),p.removeListener("error",C),p.removeListener("end",C),p.removeListener("close",C),f)return e(null,p);f=!0,y=Buffer.concat(h),Il(y,process.pid,0),p.on("error",()=>{}),p.destroy(),$()}}function C(){e(new Error("Problem negotiating cygwin unix socket security"))}function $(){p=new Cl,p.on("connect",P),p.on("data",q),p.on("error",C),p.on("end",C),p.on("close",C),p.connect(E)}})}}})(),i0=/^[/\\][/\\]\.[/\\]pipe[/\\].+/;function Bl(n){return process.platform==="win32"&&!i0.test(n)?n==="pageant"?new vl:new Nl(n):new Ur(n)}var ca=(()=>{function l(b){let w;for(;b[P].length;){let k=b[P][0][f];if(k===void 0)break;b[P].shift(),w=b.push(k)}return w}let u=Symbol("Inbound Request Type"),f=Symbol("Inbound Request Response"),h=Symbol("Inbound Request Context");class p{constructor(w,k){this[u]=w,this[f]=void 0,this[h]=k}hasResponded(){return this[f]!==void 0}getType(){return this[u]}getContext(){return this[h]}}function y(b,w,k){return w[f]=k,l(b)}function E(b){if(b[C]=null,b[q]===0){let w=b[P];if(w&&w.length){b[P]=[];for(let k of w)k.cb(new Error("No reply from server"))}}try{b.end()}catch{}setImmediate(()=>{b[v]||b.emit("end"),b[F]||b.emit("close")})}function S(){this[F]=!0}function x(){this[v]=!0}let P=Symbol("Requests"),q=Symbol("Agent Protocol Role"),C=Symbol("Agent Protocol Buffer"),$=Symbol("Agent Protocol Current Message Length"),F=Symbol("Agent Protocol Closed"),v=Symbol("Agent Protocol Ended");return class extends kl{constructor(w){super({autoDestroy:!0,emitClose:!1}),this[q]=w?0:1,this[P]=[],this[C]=null,this[$]=-1,this.once("end",x),this.once("close",S)}_read(w){}_write(w,k,N){this[C]===null?this[C]=w:this[C]=n0(this[C],w);let R=this[C],ie=R.length,j=0;for(;j<ie&&!(ie<5||(this[$]===-1&&(this[$]=ua(R,j)),ie<4+this[$]));){let X=R[j+=4];if(++j,this[q]===0){if(this[P].length===0)return N(new Error("Received unexpected message from server"));let re=this[P].shift();switch(X){case 5:re.cb(new Error("Agent responded with failure"));break;case 12:{if(re.type!==11)return N(new Error("Agent responded with wrong message type"));xt.init(R,j);let fe=xt.readUInt32BE();if(fe===void 0)return xt.clear(),N(new Error("Malformed agent response"));let H=[];for(let B=0;B<fe;++B){let L=xt.readString();if(L===void 0)return xt.clear(),N(new Error("Malformed agent response"));let z=xt.readString(!0);if(z===void 0)return xt.clear(),N(new Error("Malformed agent response"));L=wi(L),!(L instanceof Error)&&(L.comment=L.comment||z,H.push(L))}j=xt.pos(),xt.clear(),re.cb(null,H);break}case 14:{if(re.type!==13)return N(new Error("Agent responded with wrong message type"));xt.init(R,j);let fe=xt.readString();if(j=xt.pos(),xt.clear(),fe===void 0)return N(new Error("Malformed agent response"));if(xt.init(fe,0),xt.readString(!0),fe=xt.readString(),xt.clear(),fe===void 0)return N(new Error("Malformed OpenSSH signature format"));re.cb(null,fe);break}default:return N(new Error("Agent responded with unsupported message type"))}}else switch(X){case 11:{let re=new p(X);this[P].push(re),this.emit("identities",re);break}case 13:{xt.init(R,j);let re=xt.readString(),fe=xt.readString(),H=xt.readUInt32BE();if(j=xt.pos(),xt.clear(),H===void 0){let ne=new p(X);return this[P].push(ne),this.failureReply(ne)}if(re=wi(re),re instanceof Error){let ne=new p(X);return this[P].push(ne),this.failureReply(ne)}let B={hash:void 0},L;re.type==="ssh-rsa"&&(H&2?(L="rsa-sha2-256",B.hash="sha256"):H&4&&(L="rsa-sha2-512",B.hash="sha512")),L===void 0&&(L=re.type);let z=new p(X,L);this[P].push(z),this.emit("sign",z,re,fe,B);break}default:{let re=new p(X);this[P].push(re),this.failureReply(re)}}if(this[$]=-1,j===ie){this[C]=null;break}else this[C]=R=R.slice(j),ie=R.length,j=0}N()}_destroy(w,k){E(this),k()}_final(w){E(this),w()}sign(w,k,N,R){if(this[q]!==0)throw new Error("Client-only method called with server role");typeof N=="function"?(R=N,N=void 0):(typeof N!="object"||N===null)&&(N=void 0);let ie=0;if(w=wi(w),w instanceof Error)throw new Error("Invalid public key argument");if(w.type==="ssh-rsa"&&N)switch(N.hash){case"sha256":ie=2;break;case"sha512":ie=4;break}w=w.getPublicSSH();let j=13,X=w.length,re=k.length,fe=0,H=Buffer.allocUnsafe(9+X+4+re+4);return rn(H,H.length-4,fe),H[fe+=4]=j,rn(H,X,++fe),w.copy(H,fe+=4),rn(H,re,fe+=X),k.copy(H,fe+=4),rn(H,ie,fe+=re),typeof R!="function"&&(R=aa),this[P].push({type:j,cb:R}),this.push(H)}getIdentities(w){if(this[q]!==0)throw new Error("Client-only method called with server role");let k=11,N=0,R=Buffer.allocUnsafe(5);return rn(R,R.length-4,N),R[N+=4]=k,typeof w!="function"&&(w=aa),this[P].push({type:k,cb:w}),this.push(R)}failureReply(w){if(this[q]!==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,N=Buffer.allocUnsafe(5);return rn(N,N.length-4,k),N[k+=4]=5,y(this,w,N)}getIdentitiesReply(w,k){if(this[q]!==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 N=4,R=[];for(let X=0;X<k.length;++X){let re=k[X];if(typeof re!="object"||re===null)throw new Error(`Invalid key entry: ${re}`);let fe,H;if(wl(re))fe=re;else if(wl(re.pubKey))fe=re.pubKey;else if(typeof re.pubKey!="object"||re.pubKey===null||({pubKey:fe,comment:H}=re.pubKey,fe=wi(fe),fe instanceof Error))continue;H=fe.comment||H,fe=fe.getPublicSSH(),N+=4+fe.length,H&&typeof H=="string"?H=Buffer.from(H):Buffer.isBuffer(H)||(H=r0),N+=4+H.length,R.push({pubKey:fe,comment:H})}let ie=0,j=Buffer.allocUnsafe(5+N);rn(j,j.length-4,ie),j[ie+=4]=12,rn(j,R.length,++ie),ie+=4;for(let X=0;X<R.length;++X){let{pubKey:re,comment:fe}=R[X];rn(j,re.length,ie),re.copy(j,ie+=4),rn(j,fe.length,ie+=re.length),ie+=4,fe.length&&(fe.copy(j,ie),ie+=fe.length)}return y(this,w,j)}signReply(w,k){if(this[q]!==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 N=0,R=w.getContext(),ie=Buffer.byteLength(R),j=Buffer.allocUnsafe(13+ie+4+k.length);return rn(j,j.length-4,N),j[N+=4]=14,rn(j,4+ie+4+k.length,++N),rn(j,ie,N+=4),j.utf8Write(R,N+=4,ie),rn(j,k.length,N+=ie),k.copy(j,N+=4),y(this,w,j)}}})(),oa=Symbol("Agent"),Sn=Symbol("Agent Keys"),Fn=Symbol("Agent Keys Index"),Dr=Symbol("Agent Init Callbacks"),la=class{constructor(t){if(typeof t=="string")t=Bl(t);else if(!Rl(t))throw new Error("Invalid agent argument");this[oa]=t,this[Sn]=null,this[Fn]=-1,this[Dr]=null}init(t){if(typeof t!="function"&&(t=aa),this[Sn]===null)if(this[Dr]===null){this[Dr]=[t];let e=(...r)=>{process.nextTick(()=>{let s=this[Dr];this[Dr]=null;for(let i of s)i(...r)})};this[oa].getIdentities(Ii((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=wi(o),!(o instanceof Error)&&i.push(o);this[Sn]=i,this[Fn]=-1,e()}))}else this[Dr].push(t);else process.nextTick(t)}nextKey(){return this[Sn]===null||++this[Fn]>=this[Sn].length?!1:this[Sn][this[Fn]]}currentKey(){return this[Sn]===null||this[Fn]>=this[Sn].length?null:this[Sn][this[Fn]]}pos(){return this[Sn]===null||this[Fn]>=this[Sn].length?-1:this[Fn]}reset(){this[Fn]=-1}sign(...t){this[oa].sign(...t)}};function Rl(n){return n instanceof Ci}Pl.exports={AgentContext:la,AgentProtocol:ca,BaseAgent:Ci,createAgent:Bl,CygwinAgent:Nl,isAgent:Rl,OpenSSHAgent:Ur,PageantAgent:vl}});var Aa=lt((lE,Tl)=>{"use strict";var{kMaxLength:s0}=require("buffer"),{createInflate:o0,constants:{DEFLATE:a0,INFLATE:c0,Z_DEFAULT_CHUNK:l0,Z_DEFAULT_COMPRESSION:u0,Z_DEFAULT_MEMLEVEL:f0,Z_DEFAULT_STRATEGY:d0,Z_DEFAULT_WINDOWBITS:h0,Z_PARTIAL_FLUSH:p0}}=require("zlib"),m0=o0()._handle.constructor;function g0(){throw new Error("Should not get here")}function A0(n,t,e){let r=this._owner,s=new Error(n);s.errno=t,s.code=e,r._err=s}function ga(n){n._handle&&(n._handle.close(),n._handle=null)}var Es=class{constructor(t){let e=h0,r=u0,s=f0,i=d0,o=void 0;this._err=void 0,this._writeState=new Uint32Array(2),this._chunkSize=l0,this._maxOutputLength=s0,this._outBuffer=Buffer.allocUnsafe(this._chunkSize),this._outOffset=0,this._handle=new m0(t),this._handle._owner=this,this._handle.onerror=A0,this._handle.init(e,r,s,i,this._writeState,g0,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,u=0,f=this._writeState,h=this._outBuffer,p=this._outOffset,y=this._chunkSize;for(;;){if(r.writeSync(p0,t,o,s,h,p,i),this._err)throw this._err;a=f[0],c=f[1];let S=s-c,x=i-a;if(x>0){let P=p===0&&x===h.length?h:h.slice(p,p+x);if(p+=x,l?l.push===void 0?l=[l,P]:l.push(P):l=P,u+=P.byteLength,u>this._maxOutputLength)throw ga(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>=y)&&(i=y,p=0,h=Buffer.allocUnsafe(y)),a===0)o+=S,s=c;else break}if(this._outBuffer=h,this._outOffset=p,u===0&&(l=Buffer.alloc(0)),e)return l.totalLen=u,l;if(l.push===void 0)return l;let E=Buffer.allocUnsafe(u);for(let S=0,x=0;S<l.length;++S){let P=l[S];E.set(P,x),x+=P.length}return E}},da=class{constructor(t){this.allocStart=0,this.allocStartKEX=0,this._protocol=t,this._zlib=new Es(a0)}cleanup(){this._zlib&&ga(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}},ha=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}},pa=class{constructor(){this._zlib=new Es(c0)}cleanup(){this._zlib&&ga(this._zlib)}read(t){return this._zlib.writeSync(t,!1)}},ma=class{cleanup(){}read(t){return t}};Tl.exports={PacketReader:ma,PacketWriter:ha,ZlibPacketReader:pa,ZlibPacketWriter:da}});var Ul=lt((uE,Dl)=>{"use strict";var{bufferSlice:ya,bufferParser:U,doFatalError:At,sigSSHToASN1:Ol,writeUInt32BE:Ml}=En(),{CHANNEL_OPEN_FAILURE:y0,COMPAT:E0,MESSAGE:Et,TERMINAL_MODE:Ll}=Un(),{parseKey:_0}=Xn(),b0=Array.from(Object.entries(Ll)).reduce((n,[t,e])=>({...n,[t]:e}),{});Dl.exports={[Et.DISCONNECT]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r=U.readString(!0),s=U.readString();if(U.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)},[Et.IGNORE]:(n,t)=>{n._debug&&n._debug("Inbound: Received IGNORE")},[Et.UNIMPLEMENTED]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE();if(U.clear(),e===void 0)return At(n,"Inbound: Malformed UNIMPLEMENTED packet");n._debug&&n._debug(`Inbound: Received UNIMPLEMENTED (seqno ${e})`)},[Et.DEBUG]:(n,t)=>{U.init(t,1);let e=U.readBool(),r=U.readString(!0),s=U.readString();if(U.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)},[Et.SERVICE_REQUEST]:(n,t)=>{U.init(t,1);let e=U.readString(!0);if(U.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)},[Et.SERVICE_ACCEPT]:(n,t)=>{U.init(t,1);let e=U.readString(!0);if(U.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)},[Et.EXT_INFO]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r;if(e!==void 0){r=[];for(let i=0;i<e;++i){let o=U.readString(!0),a=U.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(U.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)},[Et.USERAUTH_REQUEST]:(n,t)=>{U.init(t,1);let e=U.readString(!0),r=U.readString(!0),s=U.readString(!0),i,o;switch(s){case"none":i=null;break;case"password":{let c=U.readBool();if(c!==void 0&&(i=U.readString(!0),i!==void 0&&c)){let l=U.readString(!0);l!==void 0?i={oldPassword:i,newPassword:l}:i=void 0}break}case"publickey":{let c=U.readBool();if(c!==void 0){let l=U.readString(!0),u=l,f=U.readString(),h;switch(l){case"rsa-sha2-256":u="ssh-rsa",h="sha256";break;case"rsa-sha2-512":u="ssh-rsa",h="sha512";break}if(c){let p=U.pos(),y=U.readString();if(y!==void 0&&(y.length>4+l.length+4&&y.utf8Slice(4,4+l.length)===l&&(y=ya(y,4+l.length+4)),y=Ol(y,u),y)){let E=n._kex.sessionID,S=Buffer.allocUnsafe(4+E.length+p);Ml(S,E.length,0),S.set(E,4),S.set(new Uint8Array(t.buffer,t.byteOffset,p),4+E.length),i={keyAlgo:u,key:f,signature:y,blob:S,hashAlgo:h}}}else i={keyAlgo:u,key:f,hashAlgo:h},o="publickey -- check"}break}case"hostbased":{let c=U.readString(!0),l=c,u=U.readString(),f=U.readString(!0),h=U.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 y=U.pos(),E=U.readString();if(E!==void 0&&(E.length>4+c.length+4&&E.utf8Slice(4,4+c.length)===c&&(E=ya(E,4+c.length+4)),E=Ol(E,l),E!==void 0)){let S=n._kex.sessionID,x=Buffer.allocUnsafe(4+S.length+y);Ml(x,S.length,0),x.set(S,4),x.set(new Uint8Array(t.buffer,t.byteOffset,y),4+S.length),i={keyAlgo:l,key:u,signature:E,blob:x,localHostname:f,localUsername:h,hashAlgo:p}}break}case"keyboard-interactive":U.skipString(),i=U.readList();break;default:s!==void 0&&(i=U.readRaw())}if(U.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)},[Et.USERAUTH_FAILURE]:(n,t)=>{U.init(t,1);let e=U.readList(),r=U.readBool();if(U.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)},[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)=>{U.init(t,1);let e=U.readString(!0),r=U.readString();if(U.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":{U.init(t,1);let e=U.readString(!0),r=U.readString();if(U.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":{U.init(t,1);let e=U.readString(!0),r=U.readString();if(U.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":{U.init(t,1);let e=U.readString(!0),r=U.readString(!0);U.readString();let s=U.readUInt32BE(),i;if(s!==void 0){i=new Array(s);let a;for(a=0;a<s;++a){let c=U.readString(!0),l=U.readBool();if(l===void 0)break;i[a]={prompt:c,echo:l}}a!==s&&(i=void 0)}if(U.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");U.init(t,1);let e=U.readUInt32BE(),r;if(e!==void 0){r=new Array(e);let i;for(i=0;i<e;++i){let o=U.readString(!0);if(o===void 0)break;r[i]=o}i!==e&&(r=void 0)}if(U.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)},[Et.GLOBAL_REQUEST]:(n,t)=>{U.init(t,1);let e=U.readString(!0),r=U.readBool(),s;if(r!==void 0)switch(e){case"tcpip-forward":case"cancel-tcpip-forward":{let o=U.readString(!0),a=U.readUInt32BE();a!==void 0&&(s={bindAddr:o,bindPort:a});break}case"streamlocal-forward@openssh.com":case"cancel-streamlocal-forward@openssh.com":{let o=U.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=[];U.avail()>0;){let o=U.readString();if(o===void 0){s=void 0;break}let a=_0(o);a instanceof Error||s.push(a)}break}default:s=U.readRaw()}if(U.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()},[Et.REQUEST_SUCCESS]:(n,t)=>{let e=t.length>1?ya(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)=>{U.init(t,1);let e=U.readString(!0),r=U.readUInt32BE(),s=U.readUInt32BE(),i=U.readUInt32BE(),o;switch(e){case"forwarded-tcpip":case"direct-tcpip":{let c=U.readString(!0),l=U.readUInt32BE(),u=U.readString(!0),f=U.readUInt32BE();f!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{destIP:c,destPort:l,srcIP:u,srcPort:f}});break}case"forwarded-streamlocal@openssh.com":case"direct-streamlocal@openssh.com":{let c=U.readString(!0);c!==void 0&&(o={type:e,sender:r,window:s,packetSize:i,data:{socketPath:c}});break}case"x11":{let c=U.readString(!0),l=U.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(U.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,y0.ADMINISTRATIVELY_PROHIBITED,"","")},[Et.CHANNEL_OPEN_CONFIRMATION]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r=U.readUInt32BE(),s=U.readUInt32BE(),i=U.readUInt32BE(),o=U.avail()?U.readRaw():void 0;if(U.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})},[Et.CHANNEL_OPEN_FAILURE]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r=U.readUInt32BE(),s=U.readString(!0),i=U.readString();if(U.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)},[Et.CHANNEL_WINDOW_ADJUST]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r=U.readUInt32BE();if(U.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)},[Et.CHANNEL_DATA]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r=U.readString();if(U.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)},[Et.CHANNEL_EXTENDED_DATA]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r=U.readUInt32BE(),s=U.readString();if(U.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)},[Et.CHANNEL_EOF]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE();if(U.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)},[Et.CHANNEL_CLOSE]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE();if(U.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)},[Et.CHANNEL_REQUEST]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r=U.readString(!0),s=U.readBool(),i;if(s!==void 0)switch(r){case"exit-status":i=U.readUInt32BE(),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"exit-signal":{let a,c;if(n._compatFlags&E0.OLD_EXIT){let u=U.readUInt32BE();switch(u){case 1:a="HUP";break;case 2:a="INT";break;case 3:a="QUIT";break;case 6:a="ABRT";break;case 9:a="KILL";break;case 14:a="ALRM";break;case 15:a="TERM";break;default:u!==void 0&&(a=`UNKNOWN (${u})`)}c=!1}else a=U.readString(!0),c=U.readBool(),c===void 0&&(a=void 0);let l=U.readString(!0);U.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=U.readString(!0),c=U.readUInt32BE(),l=U.readUInt32BE(),u=U.readUInt32BE(),f=U.readUInt32BE(),h=U.readString();if(h!==void 0){U.init(h,1);let p={};for(;U.avail();){let y=U.readByte();if(y===Ll.TTY_OP_END)break;let E=b0[y],S=U.readUInt32BE();if(y===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:u,height:f,modes:p})}n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"window-change":{let a=U.readUInt32BE(),c=U.readUInt32BE(),l=U.readUInt32BE(),u=U.readUInt32BE();u!==void 0&&(i={cols:a,rows:c,width:l,height:u}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"x11-req":{let a=U.readBool(),c=U.readString(!0),l=U.readString(),u=U.readUInt32BE();u!==void 0&&(i={single:a,protocol:c,cookie:l,screen:u}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"env":{let a=U.readString(!0),c=U.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=U.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"subsystem":i=U.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"signal":i=U.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${i})`);break;case"xon-xoff":i=U.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=U.avail()?U.readRaw():null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`)}if(U.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)},[Et.CHANNEL_SUCCESS]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE();if(U.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)},[Et.CHANNEL_FAILURE]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE();if(U.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 _s=lt((fE,$l)=>{"use strict";var Ea=new Array(256);[bs().HANDLERS,Ul()].forEach(n=>{for(let[t,e]of Object.entries(n))t=+t,isFinite(t)&&t>=0&&t<Ea.length&&(Ea[t]=e)});$l.exports=Ea});var bs=lt((hE,Yl)=>{"use strict";var{createDiffieHellman:S0,createDiffieHellmanGroup:x0,createECDH:w0,createHash:ba,createPublicKey:I0,diffieHellman:C0,generateKeyPairSync:k0,randomFillSync:v0}=require("crypto"),{Ber:Fl}=li(),{COMPAT:Sa,curve25519Supported:N0,DEFAULT_KEX:Hl,DEFAULT_SERVER_HOST_KEY:Ql,DEFAULT_CIPHER:Ss,DEFAULT_MAC:xs,DEFAULT_COMPRESSION:ws,DISCONNECT_REASON:Ye,MESSAGE:mt}=Un(),{CIPHER_INFO:Hr,createCipher:B0,createDecipher:R0,MAC_INFO:Wl}=Gn(),{parseDERKey:P0}=Xn(),{bufferFill:T0,bufferParser:Ge,convertSignature:O0,doFatalError:je,FastBuffer:M0,sigSSHToASN1:L0,writeUInt32BE:Qt}=En(),{PacketReader:ql,PacketWriter:Kl,ZlibPacketReader:Is,ZlibPacketWriter:Cs}=Aa(),$r,D0=2048,U0=8192,$0=Buffer.alloc(0);function Vl(n){let t;if(n._compatFlags&Sa.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),Qt(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]=mt.KEXINIT,v0(t,1,16),T0(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 zl(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&Sa.BAD_DHGEX){let C=!1;for(let $=0;$<a.length;++$)a[$].indexOf("group-exchange")!==-1&&(C||(C=!0,a=a.slice()),a.splice($--,1))}let c,l,u,f=n._debug;f&&f("Inbound: Handshake in progress"),f&&f(`Handshake: (local) KEX method: ${a}`),f&&f(`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&&(f&&f("Handshake: strict KEX mode enabled"),n._decipher.inSeqno!==1)))return f&&f("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(u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: no matching key exchange algorithm"),je(n,"Handshake failed: no matching key exchange algorithm","handshake",Ye.KEY_EXCHANGE_FAILED);e.kex=c[u],f&&f(`Handshake: KEX algorithm: ${c[u]}`),s&&(!o.kex.length||c[u]!==o.kex[0])&&(n._skipNextInboundPacket=!0);let p=i.lists.serverHostKey.array;for(f&&f(`Handshake: (local) Host key format: ${p}`),f&&f(`Handshake: (remote) Host key format: ${o.serverHostKey}`),n._server?(l=p,c=o.serverHostKey):(l=o.serverHostKey,c=p),u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: No matching host key format"),je(n,"Handshake failed: no matching host key format","handshake",Ye.KEY_EXCHANGE_FAILED);e.serverHostKey=c[u],f&&f(`Handshake: Host key format: ${c[u]}`);let y=i.lists.cs.cipher.array;for(f&&f(`Handshake: (local) C->S cipher: ${y}`),f&&f(`Handshake: (remote) C->S cipher: ${o.cs.cipher}`),n._server?(l=y,c=o.cs.cipher):(l=o.cs.cipher,c=y),u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: No matching C->S cipher"),je(n,"Handshake failed: no matching C->S cipher","handshake",Ye.KEY_EXCHANGE_FAILED);e.cs.cipher=c[u],f&&f(`Handshake: C->S Cipher: ${c[u]}`);let E=i.lists.sc.cipher.array;for(f&&f(`Handshake: (local) S->C cipher: ${E}`),f&&f(`Handshake: (remote) S->C cipher: ${o.sc.cipher}`),n._server?(l=E,c=o.sc.cipher):(l=o.sc.cipher,c=E),u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: No matching S->C cipher"),je(n,"Handshake failed: no matching S->C cipher","handshake",Ye.KEY_EXCHANGE_FAILED);e.sc.cipher=c[u],f&&f(`Handshake: S->C cipher: ${c[u]}`);let S=i.lists.cs.mac.array;if(f&&f(`Handshake: (local) C->S MAC: ${S}`),f&&f(`Handshake: (remote) C->S MAC: ${o.cs.mac}`),Hr[e.cs.cipher].authLen>0)e.cs.mac="",f&&f("Handshake: C->S MAC: <implicit>");else{for(n._server?(l=S,c=o.cs.mac):(l=o.cs.mac,c=S),u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: No matching C->S MAC"),je(n,"Handshake failed: no matching C->S MAC","handshake",Ye.KEY_EXCHANGE_FAILED);e.cs.mac=c[u],f&&f(`Handshake: C->S MAC: ${c[u]}`)}let x=i.lists.sc.mac.array;if(f&&f(`Handshake: (local) S->C MAC: ${x}`),f&&f(`Handshake: (remote) S->C MAC: ${o.sc.mac}`),Hr[e.sc.cipher].authLen>0)e.sc.mac="",f&&f("Handshake: S->C MAC: <implicit>");else{for(n._server?(l=x,c=o.sc.mac):(l=o.sc.mac,c=x),u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: No matching S->C MAC"),je(n,"Handshake failed: no matching S->C MAC","handshake",Ye.KEY_EXCHANGE_FAILED);e.sc.mac=c[u],f&&f(`Handshake: S->C MAC: ${c[u]}`)}let P=i.lists.cs.compress.array;for(f&&f(`Handshake: (local) C->S compression: ${P}`),f&&f(`Handshake: (remote) C->S compression: ${o.cs.compress}`),n._server?(l=P,c=o.cs.compress):(l=o.cs.compress,c=P),u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: No matching C->S compression"),je(n,"Handshake failed: no matching C->S compression","handshake",Ye.KEY_EXCHANGE_FAILED);e.cs.compress=c[u],f&&f(`Handshake: C->S compression: ${c[u]}`);let q=i.lists.sc.compress.array;for(f&&f(`Handshake: (local) S->C compression: ${q}`),f&&f(`Handshake: (remote) S->C compression: ${o.sc.compress}`),n._server?(l=q,c=o.sc.compress):(l=o.sc.compress,c=q),u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: No matching S->C compression"),je(n,"Handshake failed: no matching S->C compression","handshake",Ye.KEY_EXCHANGE_FAILED);e.sc.compress=c[u],f&&f(`Handshake: S->C compression: ${c[u]}`),e.cs.lang="",e.sc.lang="",n._kex&&(n._kexinit||Vl(n),n._decipher._onPayload=Gl.bind(n,{firstPacket:!1})),n._kex=F0(e,n,t),n._kex.remoteExtInfoEnabled=h,n._kex.start()}var F0=(()=>{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,u=this.convertPublicKey(this._dhData),f=this.computeSecret(this._dhData);if(f instanceof Error)return f.message=`Error while computing DH secret (${this.type}): ${f.message}`,f.level="handshake",je(this._protocol,f,Ye.KEY_EXCHANGE_FAILED);let h=ba(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 q=this.getDHParams(),C=Buffer.allocUnsafe(4);Qt(C,this._minBits,0),h.update(C),Qt(C,this._prefBits,0),h.update(C),Qt(C,this._maxBits,0),h.update(C),vn(h,q.prime),vn(h,q.generator)}vn(h,c?u:this.getPublicKey());let y=c?this.getPublicKey():u;vn(h,y),vn(h,f);let E=h.digest();if(c){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("Generating signature ...");let C=this._hostKey.sign(E,q);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=O0(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 $=this.negotiated.serverHostKey,F=Buffer.byteLength($),v=4+F+4+C.length,b=this._protocol._packetRW.write.allocStartKEX,w=this._protocol._packetRW.write.alloc(5+p.length+4+y.length+4+v,!0);if(w[b]=mt.KEXDH_REPLY,Qt(w,p.length,++b),w.set(p,b+=4),Qt(w,y.length,b+=p.length),w.set(y,b+=4),Qt(w,v,b+=y.length),Qt(w,F,b+=4),w.utf8Write($,b+=4,F),Qt(w,C.length,b+=F),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 q=Ge.readString(!0);if(!q)return je(this._protocol,"Malformed packet while reading signature","handshake",Ye.KEY_EXCHANGE_FAILED);if(q!==l.serverHostKey)return je(this._protocol,`Wrong signature type: ${q}, 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=L0(C,q)))return je(this._protocol,"Malformed signature","handshake",Ye.KEY_EXCHANGE_FAILED);let $;{Ge.init(this._hostKey,0);let b=Ge.readString(!0),w=this._hostKey.slice(Ge.pos());if(Ge.clear(),$=P0(w,b),$ instanceof Error)return $.level="handshake",je(this._protocol,$,Ye.KEY_EXCHANGE_FAILED)}let F;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":F="sha256";break;case"rsa-sha2-512":F="sha512";break}this._protocol._debug&&this._protocol._debug("Verifying signature ...");let v=$.verify(E,C,F);if(v!==!0)return v instanceof Error?this._protocol._debug&&this._protocol._debug(`Signature verification failed: ${v.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)&&ks(this);let S,x,P=q=>{if(S)return ks(this),S.outbound.seqno=this._protocol._cipher.outSeqno,this._protocol._cipher.free(),this._protocol._cipher=B0(S),this._protocol._packetRW.write=x,S=void 0,x=void 0,this._protocol._onHandshakeComplete(l),!1;this.sessionID||(this.sessionID=E);{let re=Buffer.allocUnsafe(4+f.length);Qt(re,f.length,0),re.set(f,4),f=re}let C=Hr[l.cs.cipher],$=Hr[l.sc.cipher],F=Fr(C.ivLen,this.hashName,f,E,this.sessionID,"A"),v=Fr($.ivLen,this.hashName,f,E,this.sessionID,"B"),b=Fr(C.keyLen,this.hashName,f,E,this.sessionID,"C"),w=Fr($.keyLen,this.hashName,f,E,this.sessionID,"D"),k,N;C.authLen||(k=Wl[l.cs.mac],N=Fr(k.len,this.hashName,f,E,this.sessionID,"E"));let R,ie;$.authLen||(R=Wl[l.sc.mac],ie=Fr(R.len,this.hashName,f,E,this.sessionID,"F"));let j={inbound:{onPayload:this._protocol._onPayload,seqno:this._protocol._decipher.inSeqno,decipherInfo:c?C:$,decipherIV:c?F:v,decipherKey:c?b:w,macInfo:c?k:R,macKey:c?N:ie},outbound:{onWrite:this._protocol._onWrite,seqno:this._protocol._cipher.outSeqno,cipherInfo:c?$:C,cipherIV:c?v:F,cipherKey:c?w:b,macInfo:c?R:k,macKey:c?ie:N}};this._protocol._decipher.free(),S=j,this._protocol._decipher=R0(j);let X={read:void 0,write:void 0};switch(l.cs.compress){case"zlib":c?X.read=new Is:X.write=new Cs(this._protocol);break;case"zlib@openssh.com":if(this._protocol._authenticated){c?X.read=new Is:X.write=new Cs(this._protocol);break}default:c?X.read=new ql:X.write=new Kl(this._protocol)}switch(l.sc.compress){case"zlib":c?X.write=new Cs(this._protocol):X.read=new Is;break;case"zlib@openssh.com":if(this._protocol._authenticated){c?X.write=new Cs(this._protocol):X.read=new Is;break}default:c?X.write=new Kl(this._protocol):X.read=new ql}return this._protocol._packetRW.read.cleanup(),this._protocol._packetRW.write.cleanup(),this._protocol._packetRW.read=X.read,x=X.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,q?!1:P()};if((c||a)&&(this.finish=P),!c)return P(a)}start(){if(!this._protocol._server){if(this._protocol._debug){let u;this.type==="group"?u="KEXDH_INIT":u="KEXECDH_INIT",this._protocol._debug(`Outbound: Sending ${u}`)}let a=this.getPublicKey(),c=this._protocol._packetRW.write.allocStartKEX,l=this._protocol._packetRW.write.alloc(5+a.length,!0);l[c]=mt.KEXDH_INIT,Qt(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,u=a.length;for(;a[l]===0;)++l,--u;return a[l]&128?(c=Buffer.allocUnsafe(1+u),c[0]=0,a.copy(c,1,l),c):(u!==a.length&&(c=Buffer.allocUnsafe(u),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!==mt.KEXDH_INIT)return je(this._protocol,`Received packet ${c} instead of ${mt.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 u=this._protocol._hostKeys[this.negotiated.serverHostKey];Array.isArray(u)&&(u=u[0]),this._hostKey=u,this.finish()}else{if(c!==mt.KEXDH_REPLY)return je(this._protocol,`Received packet ${c} instead of ${mt.KEXDH_REPLY}`,"handshake",Ye.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Reply"),Ge.init(a,1);let l,u,f;if((l=Ge.readString())===void 0||(u=Ge.readString())===void 0||(f=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=u,this._sig=f;let p=!1,y;if(this._protocol._hostVerifier===void 0?(y=!0,this._protocol._debug&&this._protocol._debug("Host accepted by default (no verification)")):y=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():ks(this)}}),y===void 0){++this._step;return}if(p=!0,y===!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,ks(this)}++this._step;break;case 2:return c!==mt.NEWKEYS?je(this._protocol,`Received packet ${c} instead of ${mt.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=k0("x25519"))}getPublicKey(){return this.generateKeys(),this._keys.publicKey.export({type:"spki",format:"der"}).slice(-32)}convertPublicKey(a){let c,l=0,u=a.length;for(;a[l]===0;)++l,--u;return a.length===32||u!==a.length&&(c=Buffer.allocUnsafe(u),a.copy(c,0,l),a=c),a}computeSecret(a){this.generateKeys();try{let c=new Fl.Writer;return c.startSequence(),c.startSequence(),c.writeOID("1.3.101.110"),c.endSequence(),c.startSequence(Fl.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(C0({privateKey:this._keys.privateKey,publicKey:I0({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=w0(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=D0,this._prefBits=H0(this.negotiated),this._protocol._compatFlags&Sa.BUG_DHGEX_LARGE&&(this._prefBits=Math.min(this._prefBits,4096)),this._maxBits=U0}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]=mt.KEXDH_GEX_REQUEST,Qt(c,this._minBits,++a),Qt(c,this._prefBits,a+=4),Qt(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=S0(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!==mt.KEXDH_GEX_REQUEST?je(this._protocol,`Received packet ${c} instead of `+mt.KEXDH_GEX_REQUEST,"handshake",Ye.KEY_EXCHANGE_FAILED):je(this._protocol,"Group exchange not implemented for server","handshake",Ye.KEY_EXCHANGE_FAILED);if(c!==mt.KEXDH_GEX_GROUP)return je(this._protocol,`Received packet ${c} instead of ${mt.KEXDH_GEX_GROUP}`,"handshake",Ye.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Group"),Ge.init(a,1);let l,u;if((l=Ge.readString())===void 0||(u=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,u),this.generateKeys();let f=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+f.length,!0);p[h]=mt.KEXDH_GEX_INIT,Qt(p,f.length,++h),p.set(f,h+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(p,!0)),++this._step;break}case 2:if(this._protocol._server)return c!==mt.KEXDH_GEX_INIT?je(this._protocol,`Received packet ${c} instead of ${mt.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!==mt.KEXDH_GEX_REPLY)return je(this._protocol,`Received packet ${c} instead of ${mt.KEXDH_GEX_REPLY}`,"handshake",Ye.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Reply"),this._step=1,a[0]=mt.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]=mt.KEXDH_INIT,Qt(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=x0(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(!N0)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}`)}})(),_a=(()=>{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,u,f;if(typeof a=="string")c=r,l=e[a],u=f=a;else{let p=a[0];c=r[p],f=a[1],l=e[p][f],u=`${p}.${f}`}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 \`${u}\` type: ${typeof l}`);s+=4+h.buffer.length}c[f]=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=Qt(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)=>{Qt(n,e.length,0),t.update(n),t.update(e)}})();function Fr(n,t,e,r,s,i){let o;if(n){let a=ba(t).update(e).update(r).update(i).update(s).digest();for(;a.length<n;){let c=ba(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 M0(a.buffer,a.byteOffset,n)}else o=$0;return o}function Gl(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 mt.IGNORE:case mt.UNIMPLEMENTED:case mt.DEBUG:return $r||($r=_s()),$r[e](this,t)}switch(e){case mt.DISCONNECT:return $r||($r=_s()),$r[e](this,t);case mt.KEXINIT:return n.firstPacket?(n.firstPacket=!1,zl(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 H0(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 ks(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]=mt.NEWKEYS,n._protocol._cipher.encrypt(n._protocol._packetRW.write.finalize(e,!0)),n._sentNEWKEYS=!0,n._protocol._strictMode&&(n._protocol._cipher.outSeqno=0)}}Yl.exports={KexInit:_a,kexinit:Vl,onKEXPayload:Gl,DEFAULT_KEXINIT_CLIENT:new _a({kex:Hl.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),serverHostKey:Ql,cs:{cipher:Ss,mac:xs,compress:ws,lang:[]},sc:{cipher:Ss,mac:xs,compress:ws,lang:[]}}),DEFAULT_KEXINIT_SERVER:new _a({kex:Hl.concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:Ql,cs:{cipher:Ss,mac:xs,compress:ws,lang:[]},sc:{cipher:Ss,mac:xs,compress:ws,lang:[]}}),HANDLERS:{[mt.KEXINIT]:zl}}});var jl=lt((pE,Q0)=>{Q0.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 Ca=lt((mE,lu)=>{"use strict";var{inspect:nu}=require("util"),{bindingAvailable:W0,NullCipher:q0,NullDecipher:K0}=Gn(),{COMPAT_CHECKS:V0,DISCONNECT_REASON:ru,eddsaSupported:z0,MESSAGE:Ie,SIGNALS:Xl,TERMINAL_MODE:wa}=Un(),{DEFAULT_KEXINIT_CLIENT:G0,DEFAULT_KEXINIT_SERVER:Y0,KexInit:Jl,kexinit:iu,onKEXPayload:j0}=bs(),{parseKey:Zl}=Xn(),X0=_s(),{bufferCopy:vs,bufferFill:J0,bufferSlice:su,convertSignature:eu,sendPacket:Ce,writeUInt32BE:O}=En(),{PacketReader:Z0,PacketWriter:em,ZlibPacketReader:ou,ZlibPacketWriter:au}=Aa(),tm=jl().version,nm=new Map(Object.values(ru).map(n=>[n,1])),cu=Buffer.from(`SSH-2.0-ssh2js${tm}`),rm=Buffer.from(`${cu}\r
8
- `),im=8192,sm=1024,tu=Buffer.from([Ie.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]),om=Buffer.from([wa.TTY_OP_END]);function xa(){}var Ia=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)}:xa;let o=t.onPacket;this._onPacket=typeof o=="function"?()=>{o()}:xa;let a=t.onHandshakeComplete;typeof a!="function"&&(a=xa);let c;this._onHandshakeComplete=(...p)=>{this._debug&&this._debug("Handshake completed"),c===void 0?c=!0:c=!1;let y=this._queue;if(y){this._queue=void 0,this._debug&&this._debug(`Draining outbound queue (${y.length}) ...`);for(let E=0;E<y.length;++E){let S=y[E],x=this._packetRW.write.finalize(S);if(x===S){let P=this._cipher.allocPacket(S.length);P.set(S,5),x=P}Ce(this,x)}this._debug&&this._debug("... finished draining outbound queue")}c&&this._server&&this._kex.remoteExtInfoEnabled&&hm(this),a(...p)},this._queue=void 0;let l=t.messageHandlers;typeof l=="object"&&l!==null?this._handlers=l:this._handlers={},this._onPayload=um.bind(this),this._server=!!t.server,this._banner=void 0;let u;if(this._server){if(typeof t.hostKeys!="object"||t.hostKeys===null)throw new Error("Missing server host key(s)");this._hostKeys=t.hostKeys,typeof t.greeting=="string"&&t.greeting.length&&(u=t.greeting.slice(-2)===`\r
7
+ ${e}-----END ${n} KEY-----`}function Ei(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return e.set(n,0),e.set(t,n.length),e}function ia(n,t){let e=n.length,r=n._pos||0;for(let i=0;i<t;++i){let s=e-r;if(r>=e||s<4)return!1;let o=gi(n,r);if(s<4+o)return!1;r+=4+o}return n._pos=r,!0}function _i(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(),bn("PUBLIC",e.buffer)}function bi(n,t){let e=Buffer.allocUnsafe(15+t.length+4+n.length);Ht(e,7,0),e.utf8Write("ssh-rsa",4,7);let r=11;return Ht(e,t.length,r),e.set(t,r+=4),Ht(e,n.length,r+=t.length),e.set(n,r+4),e}var Al=(()=>{function n(r,i,s,o,a,c,l,u){let f=new Re.Writer;return f.startSequence(),f.writeInt(0,Re.Integer),f.writeBuffer(r,Re.Integer),f.writeBuffer(i,Re.Integer),f.writeBuffer(s,Re.Integer),f.writeBuffer(o,Re.Integer),f.writeBuffer(a,Re.Integer),f.writeBuffer(c,Re.Integer),f.writeBuffer(l,Re.Integer),f.writeBuffer(u,Re.Integer),f.endSequence(),f.buffer}function t(r){return BigInt(`0x${r.hexSlice(0,r.length)}`)}function e(r){let i=r.toString(16);if((i.length&1)!==0)i=`0${i}`;else{let s=i.charCodeAt(0);(s===56||s===57||s>=97&&s<=102)&&(i=`00${i}`)}return Buffer.from(i,"hex")}return function(i,s,o,a,c,l){let u=t(o),f=e(u%(t(c)-1n)),h=e(u%(t(l)-1n));return bn("RSA PRIVATE",n(i,s,o,c,l,f,h,a))}})();function Si(n,t,e,r){let i=new Re.Writer;return i.startSequence(),i.startSequence(),i.writeOID("1.2.840.10040.4.1"),i.startSequence(),i.writeBuffer(n,Re.Integer),i.writeBuffer(t,Re.Integer),i.writeBuffer(e,Re.Integer),i.endSequence(),i.endSequence(),i.startSequence(Re.BitString),i.writeByte(0),i.writeBuffer(r,Re.Integer),i.endSequence(),i.endSequence(),bn("PUBLIC",i.buffer)}function xi(n,t,e,r){let i=Buffer.allocUnsafe(15+n.length+4+t.length+4+e.length+4+r.length);Ht(i,7,0),i.utf8Write("ssh-dss",4,7);let s=11;return Ht(i,n.length,s),i.set(n,s+=4),Ht(i,t.length,s+=n.length),i.set(t,s+=4),Ht(i,e.length,s+=t.length),i.set(e,s+=4),Ht(i,r.length,s+=e.length),i.set(r,s+4),i}function yl(n,t,e,r,i){let s=new Re.Writer;return s.startSequence(),s.writeInt(0,Re.Integer),s.writeBuffer(n,Re.Integer),s.writeBuffer(t,Re.Integer),s.writeBuffer(e,Re.Integer),s.writeBuffer(r,Re.Integer),s.writeBuffer(i,Re.Integer),s.endSequence(),bn("DSA PRIVATE",s.buffer)}function El(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(),bn("PUBLIC",t.buffer)}function _l(n){let t=Buffer.allocUnsafe(19+n.length);return Ht(t,11,0),t.utf8Write("ssh-ed25519",4,11),Ht(t,n.length,15),t.set(n,19),t}function Xp(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(),bn("PRIVATE",t.buffer)}function sa(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(),bn("PUBLIC",e.buffer)}function oa(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 Ht(r,19,0),r.utf8Write(`ecdsa-sha2-${e}`,4,19),Ht(r,8,23),r.utf8Write(e,27,8),Ht(r,t.length,35),r.set(t,39),r}function Jp(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(),bn("EC PRIVATE",r.buffer)}function Zp(n,t){let e=Qp(n);return e.setPrivateKey(t),e.getPublicKey()}var wi={sign:typeof ml=="function"?function(t,e){let r=this[_n];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[$n]);try{return ml(e,t,r)}catch(i){return i}}:function(t,e){let r=this[_n];if(r===null)return new Error("No private key available");(!e||typeof e!="string")&&(e=this[$n]);let i=qp(e);i.update(t);try{return i.sign(r)}catch(s){return s}},verify:typeof gl=="function"?function(t,e,r){let i=this[kn];if(i===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[$n]);try{return gl(r,t,i,e)}catch(s){return s}}:function(t,e,r){let i=this[kn];if(i===null)return new Error("No public key available");(!r||typeof r!="string")&&(r=this[$n]);let s=Kp(r);s.update(t);try{return s.verify(i,e)}catch(o){return o}},isPrivateKey:function(){return this[_n]!==null},getPrivatePEM:function(){return this[_n]},getPublicPEM:function(){return this[kn]},getPublicSSH:function(){return this[jn]},equals:function(t){let e=xl(t);return e instanceof Error?!1:this.type===e.type&&this[_n]===e[_n]&&this[kn]===e[kn]&&this[jn].equals(e[jn])}};function ms(n,t,e,r,i,s,o){this.type=n,this.comment=t,this[_n]=e,this[kn]=r,this[jn]=i,this[$n]=s,this[Dr]=o}ms.prototype=wi;{let t=function(e,r,i){let s=[];if(e.length<8)return new Error("Malformed OpenSSH private key");let o=gi(e,0),a=gi(e,4);if(o!==a)return i?new Error("OpenSSH key integrity check failed -- bad passphrase?"):new Error("OpenSSH key integrity check failed");e._pos=8;let c,l;for(c=0;c<r;++c){let f,h,p,y,E=Ne(e,e._pos,!0);if(E===void 0)return new Error("Malformed OpenSSH private key");switch(E){case"ssh-rsa":{let x=Ne(e,e._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");let P=Ne(e,e._pos);if(P===void 0)return new Error("Malformed OpenSSH private key");let q=Ne(e,e._pos);if(q===void 0)return new Error("Malformed OpenSSH private key");let C=Ne(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let $=Ne(e,e._pos);if($===void 0)return new Error("Malformed OpenSSH private key");let F=Ne(e,e._pos);if(F===void 0)return new Error("Malformed OpenSSH private key");p=_i(x,P),y=bi(x,P),h=Al(x,P,q,C,$,F),f="sha1";break}case"ssh-dss":{let x=Ne(e,e._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");let P=Ne(e,e._pos);if(P===void 0)return new Error("Malformed OpenSSH private key");let q=Ne(e,e._pos);if(q===void 0)return new Error("Malformed OpenSSH private key");let C=Ne(e,e._pos);if(C===void 0)return new Error("Malformed OpenSSH private key");let $=Ne(e,e._pos);if($===void 0)return new Error("Malformed OpenSSH private key");p=Si(x,P,q,C),y=xi(x,P,q,C),h=yl(x,P,q,C,$),f="sha1";break}case"ssh-ed25519":{if(!ra)return new Error(`Unsupported OpenSSH private key type: ${E}`);let x=Ne(e,e._pos);if(x===void 0||x.length!==32)return new Error("Malformed OpenSSH private key");let P=Ne(e,e._pos);if(P===void 0||P.length!==64)return new Error("Malformed OpenSSH private key");p=El(x),y=_l(x),h=Xp(gr(P,0,32)),f=null;break}case"ecdsa-sha2-nistp256":f="sha256",l="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":f===void 0&&(f="sha384",l="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(f===void 0&&(f="sha512",l="1.3.132.0.35"),!ia(e,1))return new Error("Malformed OpenSSH private key");let x=Ne(e,e._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");let P=Ne(e,e._pos);if(P===void 0)return new Error("Malformed OpenSSH private key");p=sa(l,x),y=oa(l,x),h=Jp(l,x,P);break}default:return new Error(`Unsupported OpenSSH private key type: ${E}`)}let S=Ne(e,e._pos,!0);if(S===void 0)return new Error("Malformed OpenSSH private key");s.push(new ms(E,S,h,p,y,f,i))}let u=0;for(c=e._pos;c<e.length;++c)if(e[c]!==++u%255)return new Error("Malformed OpenSSH private key");return s},n=/^-----BEGIN OPENSSH PRIVATE KEY-----(?:\r\n|\n)([\s\S]+)(?:\r\n|\n)-----END OPENSSH PRIVATE KEY-----$/;ms.parse=(e,r)=>{let i=n.exec(e);if(i===null)return null;let s,o=Buffer.from(i[1],"base64");if(o.length<31)return new Error("Malformed OpenSSH private key");let a=o.utf8Slice(0,15);if(a!=="openssh-key-v1\0")return new Error(`Unsupported OpenSSH key magic: ${a}`);let c=Ne(o,15,!0);if(c===void 0)return new Error("Malformed OpenSSH private key");if(c!=="none"&&Yp.indexOf(c)===-1)return new Error(`Unsupported cipher for OpenSSH key: ${c}`);let l=Ne(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 u,f,h;c!=="none"&&(u=yi[c]);let p=Ne(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=Ne(p,0);if(E===void 0||p._pos+4>p.length)return new Error("Malformed OpenSSH private key");let S=gi(p,p._pos),x=Buffer.allocUnsafe(u.keyLen+u.ivLen);if(Gp(r,r.length,E,E.length,x,x.length,S)!==0)return new Error("Failed to generate information to decrypt key");f=gr(x,0,u.keyLen),h=gr(x,u.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 y=gi(o,o._pos);if(o._pos+=4,y>0){for(let S=0;S<y;++S){let x=Ne(o,o._pos);if(x===void 0)return new Error("Malformed OpenSSH private key");if(Ne(x,0,!0)===void 0)return new Error("Malformed OpenSSH private key")}let E=Ne(o,o._pos);if(E===void 0)return new Error("Malformed OpenSSH private key");if(f!==void 0){if(E.length<u.blockLen||E.length%u.blockLen!==0)return new Error("Malformed OpenSSH private key");try{let S={authTagLength:u.authLen},x=na(u.sslName,f,h,S);if(x.setAutoPadding(!1),u.authLen>0){if(o.length-o._pos<u.authLen)return new Error("Malformed OpenSSH private key");x.setAuthTag(gr(o,o._pos,o._pos+=u.authLen))}E=Ei(x.update(E),x.final())}catch(S){return S}}if(o._pos!==o.length)return new Error("Malformed OpenSSH private key");s=t(E,y,f!==void 0)}else s=[];return s instanceof Error?s:s[0]}}function gs(n,t,e,r,i,s,o){this.type=n,this.comment=t,this[_n]=e,this[kn]=r,this[jn]=i,this[$n]=s,this[Dr]=o}gs.prototype=wi;{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-----$/;gs.parse=(t,e)=>{let r=n.exec(t);if(r===null)return null;let i=Buffer.from(r[3],"base64"),s=r[2],o=!1;if(s!==void 0){s=s.split(/\r\n|\n/g);for(let y=0;y<s.length;++y){let E=s[y],S=E.indexOf(":");if(E.slice(0,S)==="DEK-Info"){let x=E.slice(S+2);if(S=x.indexOf(","),S===-1)continue;let P=x.slice(0,S).toLowerCase();if(zp.indexOf(P)===-1)return new Error(`Cipher (${P}) not supported for encrypted OpenSSH private key`);let q=ta[P];if(!q)return new Error(`Cipher (${P}) not supported for encrypted OpenSSH private key`);let C=Buffer.from(x.slice(S+1),"hex");if(C.length!==q.ivLen)return new Error("Malformed encrypted OpenSSH private key");if(!e)return new Error("Encrypted OpenSSH private key detected, but no passphrase given");let $=gr(C,0,8),F=Ai("md5").update(e).update($).digest();for(;F.length<q.keyLen;)F=Ei(F,Ai("md5").update(F).update(e).update($).digest());F.length>q.keyLen&&(F=gr(F,0,q.keyLen));try{let v=na(P,F,C);v.setAutoPadding(!1),i=Ei(v.update(i),v.final()),o=!0}catch(v){return v}}}}let a,c,l,u,f,h,p="Malformed OpenSSH private key";switch(o&&(p+=". Bad passphrase?"),r[1]){case"RSA":a="ssh-rsa",c=bn("RSA PRIVATE",i);try{h=new Re.Reader(i),h.readSequence(),h.readInt();let y=h.readString(Re.Integer,!0);if(y===null)return new Error(p);let E=h.readString(Re.Integer,!0);if(E===null)return new Error(p);l=_i(y,E),u=bi(y,E)}catch{return new Error(p)}f="sha1";break;case"DSA":a="ssh-dss",c=bn("DSA PRIVATE",i);try{h=new Re.Reader(i),h.readSequence(),h.readInt();let y=h.readString(Re.Integer,!0);if(y===null)return new Error(p);let E=h.readString(Re.Integer,!0);if(E===null)return new Error(p);let S=h.readString(Re.Integer,!0);if(S===null)return new Error(p);let x=h.readString(Re.Integer,!0);if(x===null)return new Error(p);l=Si(y,E,S,x),u=xi(y,E,S,x)}catch{return new Error(p)}f="sha1";break;case"EC":{let y,E,S;try{h=new Re.Reader(i),h.readSequence(),h.readInt(),E=h.readString(Re.OctetString,!0),h.readByte();let P=h.readLength();if(P!==null){if(h._offset=P,S=h.readOID(),S===null)return new Error(p);switch(S){case"1.2.840.10045.3.1.7":y="prime256v1",a="ecdsa-sha2-nistp256",f="sha256";break;case"1.3.132.0.34":y="secp384r1",a="ecdsa-sha2-nistp384",f="sha384";break;case"1.3.132.0.35":y="secp521r1",a="ecdsa-sha2-nistp521",f="sha512";break;default:return new Error(`Unsupported private key EC OID: ${S}`)}}else return new Error(p)}catch{return new Error(p)}c=bn("EC PRIVATE",i);let x=Zp(y,E);l=sa(S,x),u=oa(S,x);break}}return new gs(a,"",c,l,u,f,o)}}function As(n,t,e,r,i,s,o){this.type=n,this.comment=t,this[_n]=e,this[kn]=r,this[jn]=i,this[$n]=s,this[Dr]=o}As.prototype=wi;{let n=Buffer.alloc(0),t=Buffer.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),e=Buffer.from([0,0,0,0]),r=Buffer.from([0,0,0,1]),i=/^PuTTY-User-Key-File-2: (ssh-(?:rsa|dss))\r?\nEncryption: (aes256-cbc|none)\r?\nComment: ([^\r\n]*)\r?\nPublic-Lines: \d+\r?\n([\s\S]+?)\r?\nPrivate-Lines: \d+\r?\n([\s\S]+?)\r?\nPrivate-MAC: ([^\r\n]+)/;As.parse=(s,o)=>{let a=i.exec(s);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 u=Buffer.from(a[5],"base64");if(l){let k=yi[c],N=Ei(Ai("sha1").update(e).update(o).digest(),Ai("sha1").update(r).update(o).digest());N.length>k.keyLen&&(N=gr(N,0,k.keyLen));try{let R=na(k.sslName,N,t);R.setAutoPadding(!1),u=Ei(R.update(u),R.final())}catch(R){return R}}let f=a[1],h=a[3],p=Buffer.from(a[4],"base64"),y=a[6],E=f.length,S=c.length,x=Buffer.byteLength(h),P=p.length,q=u.length,C=Buffer.allocUnsafe(4+E+4+S+4+x+4+P+4+q),$=0;if(Ht(C,E,$),C.utf8Write(f,$+=4,E),Ht(C,S,$+=E),C.utf8Write(c,$+=4,S),Ht(C,x,$+=S),C.utf8Write(h,$+=4,x),Ht(C,P,$+=x),C.set(p,$+=4),Ht(C,q,$+=P),C.set(u,$+4),o||(o=n),Wp("sha1",Ai("sha1").update("putty-private-key-file-mac-key").update(o).digest()).update(C).digest("hex")!==y)return l?new Error("PPK private key integrity check failed -- bad passphrase?"):new Error("PPK private key integrity check failed");let v,b,w;switch(p._pos=0,ia(p,1),f){case"ssh-rsa":{let k=Ne(p,p._pos);if(k===void 0)return new Error("Malformed PPK public key");let N=Ne(p,p._pos);if(N===void 0)return new Error("Malformed PPK public key");let R=Ne(u,0);if(R===void 0)return new Error("Malformed PPK private key");let ie=Ne(u,u._pos);if(ie===void 0)return new Error("Malformed PPK private key");let j=Ne(u,u._pos);if(j===void 0)return new Error("Malformed PPK private key");let X=Ne(u,u._pos);if(X===void 0)return new Error("Malformed PPK private key");v=_i(N,k),b=bi(N,k),w=Al(N,k,R,X,ie,j);break}case"ssh-dss":{let k=Ne(p,p._pos);if(k===void 0)return new Error("Malformed PPK public key");let N=Ne(p,p._pos);if(N===void 0)return new Error("Malformed PPK public key");let R=Ne(p,p._pos);if(R===void 0)return new Error("Malformed PPK public key");let ie=Ne(p,p._pos);if(ie===void 0)return new Error("Malformed PPK public key");let j=Ne(u,0);if(j===void 0)return new Error("Malformed PPK private key");v=Si(k,N,R,ie),b=xi(k,N,R,ie),w=yl(k,N,R,ie,j);break}}return new As(f,h,w,v,b,"sha1",l)}}function Es(n,t,e,r,i){this.type=n,this.comment=t,this[_n]=null,this[kn]=e,this[jn]=r,this[$n]=i,this[Dr]=!1}Es.prototype=wi;{let n;ra?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].*)?)$/,Es.parse=t=>{let e=n.exec(t);if(e===null)return null;let r=e[1],i=e[2],s=Buffer.from(e[3],"base64"),o=e[4]||"",a=Ne(s,s._pos,!0);return a===void 0||a.indexOf(i)!==0?new Error("Malformed OpenSSH public key"):aa(s,i,o,r)}}function ys(n,t,e,r,i){this.type=n,this.comment=t,this[_n]=null,this[kn]=e,this[jn]=r,this[$n]=i,this[Dr]=!1}ys.prototype=wi;{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;ys.parse=i=>{let s=n.exec(i);if(s===null)return null;let o=s[1],a=0,c="";for(;s=e.exec(o);){let p=s[1],y=s[2].replace(r,"");if(y.length>1024)return e.lastIndex=0,new Error("Malformed RFC4716 public key");a=e.lastIndex,p.toLowerCase()==="comment"&&(c=y,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 u=Ne(l,0,!0);if(u===void 0)return new Error("Malformed RFC4716 public key");let f=null,h=null;switch(u){case"ssh-rsa":{let p=Ne(l,l._pos);if(p===void 0)return new Error("Malformed RFC4716 public key");let y=Ne(l,l._pos);if(y===void 0)return new Error("Malformed RFC4716 public key");f=_i(y,p),h=bi(y,p);break}case"ssh-dss":{let p=Ne(l,l._pos);if(p===void 0)return new Error("Malformed RFC4716 public key");let y=Ne(l,l._pos);if(y===void 0)return new Error("Malformed RFC4716 public key");let E=Ne(l,l._pos);if(E===void 0)return new Error("Malformed RFC4716 public key");let S=Ne(l,l._pos);if(S===void 0)return new Error("Malformed RFC4716 public key");f=Si(p,y,E,S),h=xi(p,y,E,S);break}default:return new Error("Malformed RFC4716 public key")}return new ys(u,c,f,h,"sha1")}}function aa(n,t,e,r){if(!bl(t))return new Error(`Unsupported OpenSSH public key type: ${t}`);let i,s,o=null,a=null;switch(t){case"ssh-rsa":{let c=Ne(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let l=Ne(n,n._pos);if(l===void 0)return new Error("Malformed OpenSSH public key");o=_i(l,c),a=bi(l,c),i="sha1";break}case"ssh-dss":{let c=Ne(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");let l=Ne(n,n._pos);if(l===void 0)return new Error("Malformed OpenSSH public key");let u=Ne(n,n._pos);if(u===void 0)return new Error("Malformed OpenSSH public key");let f=Ne(n,n._pos);if(f===void 0)return new Error("Malformed OpenSSH public key");o=Si(c,l,u,f),a=xi(c,l,u,f),i="sha1";break}case"ssh-ed25519":{let c=Ne(n,n._pos||0);if(c===void 0||c.length!==32)return new Error("Malformed OpenSSH public key");o=El(c),a=_l(c),i=null;break}case"ecdsa-sha2-nistp256":i="sha256",s="1.2.840.10045.3.1.7";case"ecdsa-sha2-nistp384":i===void 0&&(i="sha384",s="1.3.132.0.34");case"ecdsa-sha2-nistp521":{if(i===void 0&&(i="sha512",s="1.3.132.0.35"),!ia(n,1))return new Error("Malformed OpenSSH public key");let c=Ne(n,n._pos||0);if(c===void 0)return new Error("Malformed OpenSSH public key");o=sa(s,c),a=oa(s,c);break}default:return new Error(`Unsupported OpenSSH public key type: ${t}`)}return new Es(r,e,o,a,i)}function bl(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(ra)return!0;default:return!1}}function Sl(n){return n?typeof n[Dr]=="boolean":!1}function xl(n,t){if(Sl(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=ms.parse(n,t))!==null||(r=gs.parse(n,t))!==null||(r=As.parse(n,t))!==null||(r=Es.parse(n))!==null||(r=ys.parse(n))!==null)return r;if(e){ps.init(e,0);let i=ps.readString(!0);i!==void 0&&(n=ps.readRaw(),n!==void 0&&(r=aa(n,i,"",i),r instanceof Error&&(r=null))),ps.clear()}return r||new Error("Unsupported key format")}wl.exports={isParsedKey:Sl,isSupportedKeyType:bl,parseDERKey:(n,t)=>aa(n,t,"",t),parseKey:xl}});var ha=lt((fE,Ol)=>{"use strict";var{Socket:vl}=require("net"),{Duplex:Nl}=require("stream"),{resolve:e0}=require("path"),{readFile:Il}=require("fs"),{execFile:t0,spawn:n0}=require("child_process"),{isParsedKey:Cl,parseKey:Ii}=Xn(),{makeBufferParser:r0,readUInt32BE:da,writeUInt32BE:rn,writeUInt32LE:kl}=En();function Ci(n){let t=!1;return(...e)=>{t||(t=!0,n(...e))}}function i0(n,t){let e=Buffer.allocUnsafe(n.length+t.length);return n.copy(e,0),t.copy(e,n.length),e}function la(){}var s0=Buffer.alloc(0),xt=r0(),ki=class{getIdentities(t){t(new Error("Missing getIdentities() implementation"))}sign(t,e,r,i){typeof r=="function"&&(i=r),i(new Error("Missing sign() implementation"))}},$r=class extends ki{constructor(t){super(),this.socketPath=t}getStream(t){t=Ci(t);let e=new vl;e.on("connect",()=>{t(null,e)}),e.on("close",r).on("end",r).on("error",r),e.connect(this.socketPath);function r(){try{e.destroy()}catch{}t(new Error("Failed to connect to agent"))}}getIdentities(t){t=Ci(t),this.getStream((e,r)=>{function i(o){if(r)try{r.destroy()}catch{}o||(o=new Error("Failed to retrieve identities from agent")),t(o)}if(e)return i(e);let s=new ua(!0);s.on("error",i),s.pipe(r).pipe(s),r.on("close",i).on("end",i).on("error",i),s.getIdentities((o,a)=>{if(o)return i(o);try{r.destroy()}catch{}t(null,a)})})}sign(t,e,r,i){typeof r=="function"?(i=r,r=void 0):(typeof r!="object"||r===null)&&(r=void 0),i=Ci(i),this.getStream((s,o)=>{function a(l){if(o)try{o.destroy()}catch{}l||(l=new Error("Failed to sign data with agent")),i(l)}if(s)return a(s);let c=new ua(!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,u)=>{if(l)return a(l);try{o.destroy()}catch{}i(null,u)})})}},Bl=(()=>{let o=e0(__dirname,"..","util/pagent.exe"),a={10:new Error("Invalid pagent.exe arguments"),11:new Error("Pageant is not running"),12:new Error("pagent.exe could not create an mmap"),13:new Error("pagent.exe could not set mode for stdin"),14:new Error("pagent.exe could not set mode for stdout"),15:new Error("pagent.exe did not get expected input payload")};function c(u){u.buffer=null,u.proc&&(u.proc.kill(),u.proc=void 0)}class l extends Nl{constructor(){super(),this.proc=void 0,this.buffer=null}_read(f){}_write(f,h,p){if(this.buffer===null)this.buffer=f;else{let x=Buffer.allocUnsafe(this.buffer.length+f.length);this.buffer.copy(x,0),f.copy(x,this.buffer.length),this.buffer=x}if(this.buffer.length<4)return p();let y=da(this.buffer,0);if(this.buffer.length-4<y)return p();if(f=this.buffer.slice(0,4+y),this.buffer.length>4+y)return p(new Error("Unexpected multiple agent requests"));this.buffer=null;let E,S=this.proc=n0(o,[f.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(f)}_final(f){c(this),f()}_destroy(f,h){c(this),h()}}return class extends $r{getStream(f){f(null,new l)}}})(),Rl=(()=>{let n=/^!<socket >(\d+) s ([A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8})/;return class extends $r{getStream(e){e=Ci(e);let r=this.socketPath,i=!1;Il(r,function s(o,a){if(o){if(i)return e(new Error("Invalid cygwin unix socket path"));t0("cygpath",["-w",r],(F,v,b)=>{if(F||v.length===0)return e(new Error("Invalid cygwin unix socket path"));i=!0,r=v.toString().replace(/[\r\n]/g,""),Il(r,s)});return}let c=n.exec(a.toString("ascii"));if(!c)return e(new Error("Malformed cygwin unix socket file"));let l,u=0,f=!1,h=[],p,y=Buffer.alloc(12),E=parseInt(c[1],10),S=c[2].replace(/-/g,""),x=Buffer.allocUnsafe(16);for(let F=0,v=0;v<32;++F,v+=2)x[F]=parseInt(S.substring(v,v+2),16);for(let F=0;F<16;F+=4)kl(x,da(x,F),F);$();function P(){u=0,l="secret",p.write(x)}function q(F){if(u+=F.length,l==="secret"){u===16&&(u=0,l="creds",p.write(y));return}if(l==="creds"&&(f||h.push(F),u===12)){if(p.removeListener("connect",P),p.removeListener("data",q),p.removeListener("error",C),p.removeListener("end",C),p.removeListener("close",C),f)return e(null,p);f=!0,y=Buffer.concat(h),kl(y,process.pid,0),p.on("error",()=>{}),p.destroy(),$()}}function C(){e(new Error("Problem negotiating cygwin unix socket security"))}function $(){p=new vl,p.on("connect",P),p.on("data",q),p.on("error",C),p.on("end",C),p.on("close",C),p.connect(E)}})}}})(),o0=/^[/\\][/\\]\.[/\\]pipe[/\\].+/;function Pl(n){return process.platform==="win32"&&!o0.test(n)?n==="pageant"?new Bl:new Rl(n):new $r(n)}var ua=(()=>{function l(b){let w;for(;b[P].length;){let k=b[P][0][f];if(k===void 0)break;b[P].shift(),w=b.push(k)}return w}let u=Symbol("Inbound Request Type"),f=Symbol("Inbound Request Response"),h=Symbol("Inbound Request Context");class p{constructor(w,k){this[u]=w,this[f]=void 0,this[h]=k}hasResponded(){return this[f]!==void 0}getType(){return this[u]}getContext(){return this[h]}}function y(b,w,k){return w[f]=k,l(b)}function E(b){if(b[C]=null,b[q]===0){let w=b[P];if(w&&w.length){b[P]=[];for(let k of w)k.cb(new Error("No reply from server"))}}try{b.end()}catch{}setImmediate(()=>{b[v]||b.emit("end"),b[F]||b.emit("close")})}function S(){this[F]=!0}function x(){this[v]=!0}let P=Symbol("Requests"),q=Symbol("Agent Protocol Role"),C=Symbol("Agent Protocol Buffer"),$=Symbol("Agent Protocol Current Message Length"),F=Symbol("Agent Protocol Closed"),v=Symbol("Agent Protocol Ended");return class extends Nl{constructor(w){super({autoDestroy:!0,emitClose:!1}),this[q]=w?0:1,this[P]=[],this[C]=null,this[$]=-1,this.once("end",x),this.once("close",S)}_read(w){}_write(w,k,N){this[C]===null?this[C]=w:this[C]=i0(this[C],w);let R=this[C],ie=R.length,j=0;for(;j<ie&&!(ie<5||(this[$]===-1&&(this[$]=da(R,j)),ie<4+this[$]));){let X=R[j+=4];if(++j,this[q]===0){if(this[P].length===0)return N(new Error("Received unexpected message from server"));let re=this[P].shift();switch(X){case 5:re.cb(new Error("Agent responded with failure"));break;case 12:{if(re.type!==11)return N(new Error("Agent responded with wrong message type"));xt.init(R,j);let fe=xt.readUInt32BE();if(fe===void 0)return xt.clear(),N(new Error("Malformed agent response"));let H=[];for(let B=0;B<fe;++B){let L=xt.readString();if(L===void 0)return xt.clear(),N(new Error("Malformed agent response"));let z=xt.readString(!0);if(z===void 0)return xt.clear(),N(new Error("Malformed agent response"));L=Ii(L),!(L instanceof Error)&&(L.comment=L.comment||z,H.push(L))}j=xt.pos(),xt.clear(),re.cb(null,H);break}case 14:{if(re.type!==13)return N(new Error("Agent responded with wrong message type"));xt.init(R,j);let fe=xt.readString();if(j=xt.pos(),xt.clear(),fe===void 0)return N(new Error("Malformed agent response"));if(xt.init(fe,0),xt.readString(!0),fe=xt.readString(),xt.clear(),fe===void 0)return N(new Error("Malformed OpenSSH signature format"));re.cb(null,fe);break}default:return N(new Error("Agent responded with unsupported message type"))}}else switch(X){case 11:{let re=new p(X);this[P].push(re),this.emit("identities",re);break}case 13:{xt.init(R,j);let re=xt.readString(),fe=xt.readString(),H=xt.readUInt32BE();if(j=xt.pos(),xt.clear(),H===void 0){let ne=new p(X);return this[P].push(ne),this.failureReply(ne)}if(re=Ii(re),re instanceof Error){let ne=new p(X);return this[P].push(ne),this.failureReply(ne)}let B={hash:void 0},L;re.type==="ssh-rsa"&&(H&2?(L="rsa-sha2-256",B.hash="sha256"):H&4&&(L="rsa-sha2-512",B.hash="sha512")),L===void 0&&(L=re.type);let z=new p(X,L);this[P].push(z),this.emit("sign",z,re,fe,B);break}default:{let re=new p(X);this[P].push(re),this.failureReply(re)}}if(this[$]=-1,j===ie){this[C]=null;break}else this[C]=R=R.slice(j),ie=R.length,j=0}N()}_destroy(w,k){E(this),k()}_final(w){E(this),w()}sign(w,k,N,R){if(this[q]!==0)throw new Error("Client-only method called with server role");typeof N=="function"?(R=N,N=void 0):(typeof N!="object"||N===null)&&(N=void 0);let ie=0;if(w=Ii(w),w instanceof Error)throw new Error("Invalid public key argument");if(w.type==="ssh-rsa"&&N)switch(N.hash){case"sha256":ie=2;break;case"sha512":ie=4;break}w=w.getPublicSSH();let j=13,X=w.length,re=k.length,fe=0,H=Buffer.allocUnsafe(9+X+4+re+4);return rn(H,H.length-4,fe),H[fe+=4]=j,rn(H,X,++fe),w.copy(H,fe+=4),rn(H,re,fe+=X),k.copy(H,fe+=4),rn(H,ie,fe+=re),typeof R!="function"&&(R=la),this[P].push({type:j,cb:R}),this.push(H)}getIdentities(w){if(this[q]!==0)throw new Error("Client-only method called with server role");let k=11,N=0,R=Buffer.allocUnsafe(5);return rn(R,R.length-4,N),R[N+=4]=k,typeof w!="function"&&(w=la),this[P].push({type:k,cb:w}),this.push(R)}failureReply(w){if(this[q]!==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,N=Buffer.allocUnsafe(5);return rn(N,N.length-4,k),N[k+=4]=5,y(this,w,N)}getIdentitiesReply(w,k){if(this[q]!==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 N=4,R=[];for(let X=0;X<k.length;++X){let re=k[X];if(typeof re!="object"||re===null)throw new Error(`Invalid key entry: ${re}`);let fe,H;if(Cl(re))fe=re;else if(Cl(re.pubKey))fe=re.pubKey;else if(typeof re.pubKey!="object"||re.pubKey===null||({pubKey:fe,comment:H}=re.pubKey,fe=Ii(fe),fe instanceof Error))continue;H=fe.comment||H,fe=fe.getPublicSSH(),N+=4+fe.length,H&&typeof H=="string"?H=Buffer.from(H):Buffer.isBuffer(H)||(H=s0),N+=4+H.length,R.push({pubKey:fe,comment:H})}let ie=0,j=Buffer.allocUnsafe(5+N);rn(j,j.length-4,ie),j[ie+=4]=12,rn(j,R.length,++ie),ie+=4;for(let X=0;X<R.length;++X){let{pubKey:re,comment:fe}=R[X];rn(j,re.length,ie),re.copy(j,ie+=4),rn(j,fe.length,ie+=re.length),ie+=4,fe.length&&(fe.copy(j,ie),ie+=fe.length)}return y(this,w,j)}signReply(w,k){if(this[q]!==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 N=0,R=w.getContext(),ie=Buffer.byteLength(R),j=Buffer.allocUnsafe(13+ie+4+k.length);return rn(j,j.length-4,N),j[N+=4]=14,rn(j,4+ie+4+k.length,++N),rn(j,ie,N+=4),j.utf8Write(R,N+=4,ie),rn(j,k.length,N+=ie),k.copy(j,N+=4),y(this,w,j)}}})(),ca=Symbol("Agent"),Sn=Symbol("Agent Keys"),Fn=Symbol("Agent Keys Index"),Ur=Symbol("Agent Init Callbacks"),fa=class{constructor(t){if(typeof t=="string")t=Pl(t);else if(!Tl(t))throw new Error("Invalid agent argument");this[ca]=t,this[Sn]=null,this[Fn]=-1,this[Ur]=null}init(t){if(typeof t!="function"&&(t=la),this[Sn]===null)if(this[Ur]===null){this[Ur]=[t];let e=(...r)=>{process.nextTick(()=>{let i=this[Ur];this[Ur]=null;for(let s of i)s(...r)})};this[ca].getIdentities(Ci((r,i)=>{if(r)return e(r);if(!Array.isArray(i))return e(new Error("Agent implementation failed to provide keys"));let s=[];for(let o of i)o=Ii(o),!(o instanceof Error)&&s.push(o);this[Sn]=s,this[Fn]=-1,e()}))}else this[Ur].push(t);else process.nextTick(t)}nextKey(){return this[Sn]===null||++this[Fn]>=this[Sn].length?!1:this[Sn][this[Fn]]}currentKey(){return this[Sn]===null||this[Fn]>=this[Sn].length?null:this[Sn][this[Fn]]}pos(){return this[Sn]===null||this[Fn]>=this[Sn].length?-1:this[Fn]}reset(){this[Fn]=-1}sign(...t){this[ca].sign(...t)}};function Tl(n){return n instanceof ki}Ol.exports={AgentContext:fa,AgentProtocol:ua,BaseAgent:ki,createAgent:Pl,CygwinAgent:Rl,isAgent:Tl,OpenSSHAgent:$r,PageantAgent:Bl}});var Ea=lt((dE,Ml)=>{"use strict";var{kMaxLength:a0}=require("buffer"),{createInflate:c0,constants:{DEFLATE:l0,INFLATE:u0,Z_DEFAULT_CHUNK:f0,Z_DEFAULT_COMPRESSION:d0,Z_DEFAULT_MEMLEVEL:h0,Z_DEFAULT_STRATEGY:p0,Z_DEFAULT_WINDOWBITS:m0,Z_PARTIAL_FLUSH:g0}}=require("zlib"),A0=c0()._handle.constructor;function y0(){throw new Error("Should not get here")}function E0(n,t,e){let r=this._owner,i=new Error(n);i.errno=t,i.code=e,r._err=i}function ya(n){n._handle&&(n._handle.close(),n._handle=null)}var _s=class{constructor(t){let e=m0,r=d0,i=h0,s=p0,o=void 0;this._err=void 0,this._writeState=new Uint32Array(2),this._chunkSize=f0,this._maxOutputLength=a0,this._outBuffer=Buffer.allocUnsafe(this._chunkSize),this._outOffset=0,this._handle=new A0(t),this._handle._owner=this,this._handle.onerror=E0,this._handle.init(e,r,i,s,this._writeState,y0,o)}writeSync(t,e){let r=this._handle;if(!r)throw new Error("Invalid Zlib instance");let i=t.length,s=this._chunkSize-this._outOffset,o=0,a,c,l,u=0,f=this._writeState,h=this._outBuffer,p=this._outOffset,y=this._chunkSize;for(;;){if(r.writeSync(g0,t,o,i,h,p,s),this._err)throw this._err;a=f[0],c=f[1];let S=i-c,x=s-a;if(x>0){let P=p===0&&x===h.length?h:h.slice(p,p+x);if(p+=x,l?l.push===void 0?l=[l,P]:l.push(P):l=P,u+=P.byteLength,u>this._maxOutputLength)throw ya(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>=y)&&(s=y,p=0,h=Buffer.allocUnsafe(y)),a===0)o+=S,i=c;else break}if(this._outBuffer=h,this._outOffset=p,u===0&&(l=Buffer.alloc(0)),e)return l.totalLen=u,l;if(l.push===void 0)return l;let E=Buffer.allocUnsafe(u);for(let S=0,x=0;S<l.length;++S){let P=l[S];E.set(P,x),x+=P.length}return E}},pa=class{constructor(t){this.allocStart=0,this.allocStartKEX=0,this._protocol=t,this._zlib=new _s(l0)}cleanup(){this._zlib&&ya(this._zlib)}alloc(t,e){return Buffer.allocUnsafe(t)}finalize(t,e){if(this._protocol._kexinit===void 0||e){let r=this._zlib.writeSync(t,!0),i=this._protocol._cipher.allocPacket(r.totalLen);if(r.push===void 0)i.set(r,5);else for(let s=0,o=5;s<r.length;++s){let a=r[s];i.set(a,o),o+=a.length}return i}return t}},ma=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}},ga=class{constructor(){this._zlib=new _s(u0)}cleanup(){this._zlib&&ya(this._zlib)}read(t){return this._zlib.writeSync(t,!1)}},Aa=class{cleanup(){}read(t){return t}};Ml.exports={PacketReader:Aa,PacketWriter:ma,ZlibPacketReader:ga,ZlibPacketWriter:pa}});var Fl=lt((hE,$l)=>{"use strict";var{bufferSlice:_a,bufferParser:U,doFatalError:At,sigSSHToASN1:Ll,writeUInt32BE:Dl}=En(),{CHANNEL_OPEN_FAILURE:_0,COMPAT:b0,MESSAGE:Et,TERMINAL_MODE:Ul}=Un(),{parseKey:S0}=Xn(),x0=Array.from(Object.entries(Ul)).reduce((n,[t,e])=>({...n,[t]:e}),{});$l.exports={[Et.DISCONNECT]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r=U.readString(!0),i=U.readString();if(U.clear(),i===void 0)return At(n,"Inbound: Malformed DISCONNECT packet");n._debug&&n._debug(`Inbound: Received DISCONNECT (${e}, "${r}")`);let s=n._handlers.DISCONNECT;s&&s(n,e,r)},[Et.IGNORE]:(n,t)=>{n._debug&&n._debug("Inbound: Received IGNORE")},[Et.UNIMPLEMENTED]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE();if(U.clear(),e===void 0)return At(n,"Inbound: Malformed UNIMPLEMENTED packet");n._debug&&n._debug(`Inbound: Received UNIMPLEMENTED (seqno ${e})`)},[Et.DEBUG]:(n,t)=>{U.init(t,1);let e=U.readBool(),r=U.readString(!0),i=U.readString();if(U.clear(),i===void 0)return At(n,"Inbound: Malformed DEBUG packet");n._debug&&n._debug("Inbound: Received DEBUG");let s=n._handlers.DEBUG;s&&s(n,e,r)},[Et.SERVICE_REQUEST]:(n,t)=>{U.init(t,1);let e=U.readString(!0);if(U.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)},[Et.SERVICE_ACCEPT]:(n,t)=>{U.init(t,1);let e=U.readString(!0);if(U.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)},[Et.EXT_INFO]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r;if(e!==void 0){r=[];for(let s=0;s<e;++s){let o=U.readString(!0),a=U.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(U.clear(),r===void 0)return At(n,"Inbound: Malformed EXT_INFO packet");n._debug&&n._debug("Inbound: Received EXT_INFO");let i=n._handlers.EXT_INFO;i&&i(n,r)},[Et.USERAUTH_REQUEST]:(n,t)=>{U.init(t,1);let e=U.readString(!0),r=U.readString(!0),i=U.readString(!0),s,o;switch(i){case"none":s=null;break;case"password":{let c=U.readBool();if(c!==void 0&&(s=U.readString(!0),s!==void 0&&c)){let l=U.readString(!0);l!==void 0?s={oldPassword:s,newPassword:l}:s=void 0}break}case"publickey":{let c=U.readBool();if(c!==void 0){let l=U.readString(!0),u=l,f=U.readString(),h;switch(l){case"rsa-sha2-256":u="ssh-rsa",h="sha256";break;case"rsa-sha2-512":u="ssh-rsa",h="sha512";break}if(c){let p=U.pos(),y=U.readString();if(y!==void 0&&(y.length>4+l.length+4&&y.utf8Slice(4,4+l.length)===l&&(y=_a(y,4+l.length+4)),y=Ll(y,u),y)){let E=n._kex.sessionID,S=Buffer.allocUnsafe(4+E.length+p);Dl(S,E.length,0),S.set(E,4),S.set(new Uint8Array(t.buffer,t.byteOffset,p),4+E.length),s={keyAlgo:u,key:f,signature:y,blob:S,hashAlgo:h}}}else s={keyAlgo:u,key:f,hashAlgo:h},o="publickey -- check"}break}case"hostbased":{let c=U.readString(!0),l=c,u=U.readString(),f=U.readString(!0),h=U.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 y=U.pos(),E=U.readString();if(E!==void 0&&(E.length>4+c.length+4&&E.utf8Slice(4,4+c.length)===c&&(E=_a(E,4+c.length+4)),E=Ll(E,l),E!==void 0)){let S=n._kex.sessionID,x=Buffer.allocUnsafe(4+S.length+y);Dl(x,S.length,0),x.set(S,4),x.set(new Uint8Array(t.buffer,t.byteOffset,y),4+S.length),s={keyAlgo:l,key:u,signature:E,blob:x,localHostname:f,localUsername:h,hashAlgo:p}}break}case"keyboard-interactive":U.skipString(),s=U.readList();break;default:i!==void 0&&(s=U.readRaw())}if(U.clear(),s===void 0)return At(n,"Inbound: Malformed USERAUTH_REQUEST packet");o===void 0&&(o=i),n._authsQueue.push(i),n._debug&&n._debug(`Inbound: Received USERAUTH_REQUEST (${o})`);let a=n._handlers.USERAUTH_REQUEST;a&&a(n,e,r,i,s)},[Et.USERAUTH_FAILURE]:(n,t)=>{U.init(t,1);let e=U.readList(),r=U.readBool();if(U.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 i=n._handlers.USERAUTH_FAILURE;i&&i(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)=>{U.init(t,1);let e=U.readString(!0),r=U.readString();if(U.clear(),r===void 0)return At(n,"Inbound: Malformed USERAUTH_BANNER packet");n._debug&&n._debug("Inbound: Received USERAUTH_BANNER");let i=n._handlers.USERAUTH_BANNER;i&&i(n,e)},60:(n,t)=>{if(!n._authsQueue.length){n._debug&&n._debug("Inbound: Received payload type 60 without auth");return}switch(n._authsQueue[0]){case"password":{U.init(t,1);let e=U.readString(!0),r=U.readString();if(U.clear(),r===void 0)return At(n,"Inbound: Malformed USERAUTH_PASSWD_CHANGEREQ packet");n._debug&&n._debug("Inbound: Received USERAUTH_PASSWD_CHANGEREQ");let i=n._handlers.USERAUTH_PASSWD_CHANGEREQ;i&&i(n,e);break}case"publickey":{U.init(t,1);let e=U.readString(!0),r=U.readString();if(U.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 i=n._handlers.USERAUTH_PK_OK;i&&i(n,e,r);break}case"keyboard-interactive":{U.init(t,1);let e=U.readString(!0),r=U.readString(!0);U.readString();let i=U.readUInt32BE(),s;if(i!==void 0){s=new Array(i);let a;for(a=0;a<i;++a){let c=U.readString(!0),l=U.readBool();if(l===void 0)break;s[a]={prompt:c,echo:l}}a!==i&&(s=void 0)}if(U.clear(),s===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,s);break}default:n._debug&&n._debug("Inbound: Received unexpected payload type 60")}},61:(n,t)=>{if(!n._authsQueue.length){n._debug&&n._debug("Inbound: Received payload type 61 without auth");return}if(n._authsQueue[0]!=="keyboard-interactive")return At(n,"Inbound: Received unexpected payload type 61");U.init(t,1);let e=U.readUInt32BE(),r;if(e!==void 0){r=new Array(e);let s;for(s=0;s<e;++s){let o=U.readString(!0);if(o===void 0)break;r[s]=o}s!==e&&(r=void 0)}if(U.clear(),r===void 0)return At(n,"Inbound: Malformed USERAUTH_INFO_RESPONSE packet");n._debug&&n._debug("Inbound: Received USERAUTH_INFO_RESPONSE");let i=n._handlers.USERAUTH_INFO_RESPONSE;i&&i(n,r)},[Et.GLOBAL_REQUEST]:(n,t)=>{U.init(t,1);let e=U.readString(!0),r=U.readBool(),i;if(r!==void 0)switch(e){case"tcpip-forward":case"cancel-tcpip-forward":{let o=U.readString(!0),a=U.readUInt32BE();a!==void 0&&(i={bindAddr:o,bindPort:a});break}case"streamlocal-forward@openssh.com":case"cancel-streamlocal-forward@openssh.com":{let o=U.readString(!0);o!==void 0&&(i={socketPath:o});break}case"no-more-sessions@openssh.com":i=null;break;case"hostkeys-00@openssh.com":{for(i=[];U.avail()>0;){let o=U.readString();if(o===void 0){i=void 0;break}let a=S0(o);a instanceof Error||i.push(a)}break}default:i=U.readRaw()}if(U.clear(),i===void 0)return At(n,"Inbound: Malformed GLOBAL_REQUEST packet");n._debug&&n._debug(`Inbound: GLOBAL_REQUEST (${e})`);let s=n._handlers.GLOBAL_REQUEST;s?s(n,e,r,i):n.requestFailure()},[Et.REQUEST_SUCCESS]:(n,t)=>{let e=t.length>1?_a(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)=>{U.init(t,1);let e=U.readString(!0),r=U.readUInt32BE(),i=U.readUInt32BE(),s=U.readUInt32BE(),o;switch(e){case"forwarded-tcpip":case"direct-tcpip":{let c=U.readString(!0),l=U.readUInt32BE(),u=U.readString(!0),f=U.readUInt32BE();f!==void 0&&(o={type:e,sender:r,window:i,packetSize:s,data:{destIP:c,destPort:l,srcIP:u,srcPort:f}});break}case"forwarded-streamlocal@openssh.com":case"direct-streamlocal@openssh.com":{let c=U.readString(!0);c!==void 0&&(o={type:e,sender:r,window:i,packetSize:s,data:{socketPath:c}});break}case"x11":{let c=U.readString(!0),l=U.readUInt32BE();l!==void 0&&(o={type:e,sender:r,window:i,packetSize:s,data:{srcIP:c,srcPort:l}});break}default:o={type:e,sender:r,window:i,packetSize:s,data:{}}}if(U.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,_0.ADMINISTRATIVELY_PROHIBITED,"","")},[Et.CHANNEL_OPEN_CONFIRMATION]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r=U.readUInt32BE(),i=U.readUInt32BE(),s=U.readUInt32BE(),o=U.avail()?U.readRaw():void 0;if(U.clear(),s===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:i,packetSize:s,data:o})},[Et.CHANNEL_OPEN_FAILURE]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r=U.readUInt32BE(),i=U.readString(!0),s=U.readString();if(U.clear(),s===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,i)},[Et.CHANNEL_WINDOW_ADJUST]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r=U.readUInt32BE();if(U.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 i=n._handlers.CHANNEL_WINDOW_ADJUST;i&&i(n,e,r)},[Et.CHANNEL_DATA]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r=U.readString();if(U.clear(),r===void 0)return At(n,"Inbound: Malformed CHANNEL_DATA packet");n._debug&&n._debug(`Inbound: CHANNEL_DATA (r:${e}, ${r.length})`);let i=n._handlers.CHANNEL_DATA;i&&i(n,e,r)},[Et.CHANNEL_EXTENDED_DATA]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r=U.readUInt32BE(),i=U.readString();if(U.clear(),i===void 0)return At(n,"Inbound: Malformed CHANNEL_EXTENDED_DATA packet");n._debug&&n._debug(`Inbound: CHANNEL_EXTENDED_DATA (r:${e}, ${i.length})`);let s=n._handlers.CHANNEL_EXTENDED_DATA;s&&s(n,e,i,r)},[Et.CHANNEL_EOF]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE();if(U.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)},[Et.CHANNEL_CLOSE]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE();if(U.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)},[Et.CHANNEL_REQUEST]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE(),r=U.readString(!0),i=U.readBool(),s;if(i!==void 0)switch(r){case"exit-status":s=U.readUInt32BE(),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${s})`);break;case"exit-signal":{let a,c;if(n._compatFlags&b0.OLD_EXIT){let u=U.readUInt32BE();switch(u){case 1:a="HUP";break;case 2:a="INT";break;case 3:a="QUIT";break;case 6:a="ABRT";break;case 9:a="KILL";break;case 14:a="ALRM";break;case 15:a="TERM";break;default:u!==void 0&&(a=`UNKNOWN (${u})`)}c=!1}else a=U.readString(!0),c=U.readBool(),c===void 0&&(a=void 0);let l=U.readString(!0);U.skipString()!==void 0&&(s={signal:a,coreDumped:c,errorMessage:l}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${a})`);break}case"pty-req":{let a=U.readString(!0),c=U.readUInt32BE(),l=U.readUInt32BE(),u=U.readUInt32BE(),f=U.readUInt32BE(),h=U.readString();if(h!==void 0){U.init(h,1);let p={};for(;U.avail();){let y=U.readByte();if(y===Ul.TTY_OP_END)break;let E=x0[y],S=U.readUInt32BE();if(y===void 0||E===void 0||S===void 0){p=void 0;break}p[E]=S}p!==void 0&&(s={term:a,cols:c,rows:l,width:u,height:f,modes:p})}n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"window-change":{let a=U.readUInt32BE(),c=U.readUInt32BE(),l=U.readUInt32BE(),u=U.readUInt32BE();u!==void 0&&(s={cols:a,rows:c,width:l,height:u}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"x11-req":{let a=U.readBool(),c=U.readString(!0),l=U.readString(),u=U.readUInt32BE();u!==void 0&&(s={single:a,protocol:c,cookie:l,screen:u}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break}case"env":{let a=U.readString(!0),c=U.readString(!0);c!==void 0&&(s={name:a,value:c}),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${a}=${c})`);break}case"shell":s=null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break;case"exec":s=U.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${s})`);break;case"subsystem":s=U.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${s})`);break;case"signal":s=U.readString(!0),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${s})`);break;case"xon-xoff":s=U.readBool(),n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r}: ${s})`);break;case"auth-agent-req@openssh.com":s=null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`);break;default:s=U.avail()?U.readRaw():null,n._debug&&n._debug(`Inbound: CHANNEL_REQUEST (r:${e}, ${r})`)}if(U.clear(),s===void 0)return At(n,"Inbound: Malformed CHANNEL_REQUEST packet");let o=n._handlers.CHANNEL_REQUEST;o&&o(n,e,r,i,s)},[Et.CHANNEL_SUCCESS]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE();if(U.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)},[Et.CHANNEL_FAILURE]:(n,t)=>{U.init(t,1);let e=U.readUInt32BE();if(U.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 bs=lt((pE,Hl)=>{"use strict";var ba=new Array(256);[Ss().HANDLERS,Fl()].forEach(n=>{for(let[t,e]of Object.entries(n))t=+t,isFinite(t)&&t>=0&&t<ba.length&&(ba[t]=e)});Hl.exports=ba});var Ss=lt((gE,Xl)=>{"use strict";var{createDiffieHellman:w0,createDiffieHellmanGroup:I0,createECDH:C0,createHash:xa,createPublicKey:k0,diffieHellman:v0,generateKeyPairSync:N0,randomFillSync:B0}=require("crypto"),{Ber:Ql}=ui(),{COMPAT:wa,curve25519Supported:R0,DEFAULT_KEX:Wl,DEFAULT_SERVER_HOST_KEY:ql,DEFAULT_CIPHER:xs,DEFAULT_MAC:ws,DEFAULT_COMPRESSION:Is,DISCONNECT_REASON:Ye,MESSAGE:mt}=Un(),{CIPHER_INFO:Qr,createCipher:P0,createDecipher:T0,MAC_INFO:Kl}=Gn(),{parseDERKey:O0}=Xn(),{bufferFill:M0,bufferParser:Ge,convertSignature:L0,doFatalError:je,FastBuffer:D0,sigSSHToASN1:U0,writeUInt32BE:Qt}=En(),{PacketReader:Vl,PacketWriter:zl,ZlibPacketReader:Cs,ZlibPacketWriter:ks}=Ea(),Fr,$0=2048,F0=8192,H0=Buffer.alloc(0);function Gl(n){let t;if(n._compatFlags&wa.BAD_DHGEX){let e=n._offer.lists.kex,r=e.array,i=!1;for(let s=0;s<r.length;++s)r[s].includes("group-exchange")&&(i||(i=!0,r=r.slice()),r.splice(s--,1));if(i){let s=17+n._offer.totalSize+1+4,o=Buffer.from(r.join(","));s-=e.buffer.length-o.length;let a=n._offer.lists.all,c=new Uint8Array(a.buffer,a.byteOffset+4+e.buffer.length,a.length-(4+e.buffer.length));t=Buffer.allocUnsafe(s),Qt(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]=mt.KEXINIT,B0(t,1,16),M0(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 Yl(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(),i=r<t.length&&t[r]===1;Ge.clear();let s=n._offer,o=e,a=s.lists.kex.array;if(n._compatFlags&wa.BAD_DHGEX){let C=!1;for(let $=0;$<a.length;++$)a[$].indexOf("group-exchange")!==-1&&(C||(C=!0,a=a.slice()),a.splice($--,1))}let c,l,u,f=n._debug;f&&f("Inbound: Handshake in progress"),f&&f(`Handshake: (local) KEX method: ${a}`),f&&f(`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&&(f&&f("Handshake: strict KEX mode enabled"),n._decipher.inSeqno!==1)))return f&&f("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(u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: no matching key exchange algorithm"),je(n,"Handshake failed: no matching key exchange algorithm","handshake",Ye.KEY_EXCHANGE_FAILED);e.kex=c[u],f&&f(`Handshake: KEX algorithm: ${c[u]}`),i&&(!o.kex.length||c[u]!==o.kex[0])&&(n._skipNextInboundPacket=!0);let p=s.lists.serverHostKey.array;for(f&&f(`Handshake: (local) Host key format: ${p}`),f&&f(`Handshake: (remote) Host key format: ${o.serverHostKey}`),n._server?(l=p,c=o.serverHostKey):(l=o.serverHostKey,c=p),u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: No matching host key format"),je(n,"Handshake failed: no matching host key format","handshake",Ye.KEY_EXCHANGE_FAILED);e.serverHostKey=c[u],f&&f(`Handshake: Host key format: ${c[u]}`);let y=s.lists.cs.cipher.array;for(f&&f(`Handshake: (local) C->S cipher: ${y}`),f&&f(`Handshake: (remote) C->S cipher: ${o.cs.cipher}`),n._server?(l=y,c=o.cs.cipher):(l=o.cs.cipher,c=y),u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: No matching C->S cipher"),je(n,"Handshake failed: no matching C->S cipher","handshake",Ye.KEY_EXCHANGE_FAILED);e.cs.cipher=c[u],f&&f(`Handshake: C->S Cipher: ${c[u]}`);let E=s.lists.sc.cipher.array;for(f&&f(`Handshake: (local) S->C cipher: ${E}`),f&&f(`Handshake: (remote) S->C cipher: ${o.sc.cipher}`),n._server?(l=E,c=o.sc.cipher):(l=o.sc.cipher,c=E),u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: No matching S->C cipher"),je(n,"Handshake failed: no matching S->C cipher","handshake",Ye.KEY_EXCHANGE_FAILED);e.sc.cipher=c[u],f&&f(`Handshake: S->C cipher: ${c[u]}`);let S=s.lists.cs.mac.array;if(f&&f(`Handshake: (local) C->S MAC: ${S}`),f&&f(`Handshake: (remote) C->S MAC: ${o.cs.mac}`),Qr[e.cs.cipher].authLen>0)e.cs.mac="",f&&f("Handshake: C->S MAC: <implicit>");else{for(n._server?(l=S,c=o.cs.mac):(l=o.cs.mac,c=S),u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: No matching C->S MAC"),je(n,"Handshake failed: no matching C->S MAC","handshake",Ye.KEY_EXCHANGE_FAILED);e.cs.mac=c[u],f&&f(`Handshake: C->S MAC: ${c[u]}`)}let x=s.lists.sc.mac.array;if(f&&f(`Handshake: (local) S->C MAC: ${x}`),f&&f(`Handshake: (remote) S->C MAC: ${o.sc.mac}`),Qr[e.sc.cipher].authLen>0)e.sc.mac="",f&&f("Handshake: S->C MAC: <implicit>");else{for(n._server?(l=x,c=o.sc.mac):(l=o.sc.mac,c=x),u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: No matching S->C MAC"),je(n,"Handshake failed: no matching S->C MAC","handshake",Ye.KEY_EXCHANGE_FAILED);e.sc.mac=c[u],f&&f(`Handshake: S->C MAC: ${c[u]}`)}let P=s.lists.cs.compress.array;for(f&&f(`Handshake: (local) C->S compression: ${P}`),f&&f(`Handshake: (remote) C->S compression: ${o.cs.compress}`),n._server?(l=P,c=o.cs.compress):(l=o.cs.compress,c=P),u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: No matching C->S compression"),je(n,"Handshake failed: no matching C->S compression","handshake",Ye.KEY_EXCHANGE_FAILED);e.cs.compress=c[u],f&&f(`Handshake: C->S compression: ${c[u]}`);let q=s.lists.sc.compress.array;for(f&&f(`Handshake: (local) S->C compression: ${q}`),f&&f(`Handshake: (remote) S->C compression: ${o.sc.compress}`),n._server?(l=q,c=o.sc.compress):(l=o.sc.compress,c=q),u=0;u<c.length&&l.indexOf(c[u])===-1;++u);if(u===c.length)return f&&f("Handshake: No matching S->C compression"),je(n,"Handshake failed: no matching S->C compression","handshake",Ye.KEY_EXCHANGE_FAILED);e.sc.compress=c[u],f&&f(`Handshake: S->C compression: ${c[u]}`),e.cs.lang="",e.sc.lang="",n._kex&&(n._kexinit||Gl(n),n._decipher._onPayload=jl.bind(n,{firstPacket:!1})),n._kex=Q0(e,n,t),n._kex.remoteExtInfoEnabled=h,n._kex.start()}var Q0=(()=>{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,u=this.convertPublicKey(this._dhData),f=this.computeSecret(this._dhData);if(f instanceof Error)return f.message=`Error while computing DH secret (${this.type}): ${f.message}`,f.level="handshake",je(this._protocol,f,Ye.KEY_EXCHANGE_FAILED);let h=xa(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 q=this.getDHParams(),C=Buffer.allocUnsafe(4);Qt(C,this._minBits,0),h.update(C),Qt(C,this._prefBits,0),h.update(C),Qt(C,this._maxBits,0),h.update(C),vn(h,q.prime),vn(h,q.generator)}vn(h,c?u:this.getPublicKey());let y=c?this.getPublicKey():u;vn(h,y),vn(h,f);let E=h.digest();if(c){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("Generating signature ...");let C=this._hostKey.sign(E,q);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=L0(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 $=this.negotiated.serverHostKey,F=Buffer.byteLength($),v=4+F+4+C.length,b=this._protocol._packetRW.write.allocStartKEX,w=this._protocol._packetRW.write.alloc(5+p.length+4+y.length+4+v,!0);if(w[b]=mt.KEXDH_REPLY,Qt(w,p.length,++b),w.set(p,b+=4),Qt(w,y.length,b+=p.length),w.set(y,b+=4),Qt(w,v,b+=y.length),Qt(w,F,b+=4),w.utf8Write($,b+=4,F),Qt(w,C.length,b+=F),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 q=Ge.readString(!0);if(!q)return je(this._protocol,"Malformed packet while reading signature","handshake",Ye.KEY_EXCHANGE_FAILED);if(q!==l.serverHostKey)return je(this._protocol,`Wrong signature type: ${q}, 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=U0(C,q)))return je(this._protocol,"Malformed signature","handshake",Ye.KEY_EXCHANGE_FAILED);let $;{Ge.init(this._hostKey,0);let b=Ge.readString(!0),w=this._hostKey.slice(Ge.pos());if(Ge.clear(),$=O0(w,b),$ instanceof Error)return $.level="handshake",je(this._protocol,$,Ye.KEY_EXCHANGE_FAILED)}let F;switch(this.negotiated.serverHostKey){case"rsa-sha2-256":F="sha256";break;case"rsa-sha2-512":F="sha512";break}this._protocol._debug&&this._protocol._debug("Verifying signature ...");let v=$.verify(E,C,F);if(v!==!0)return v instanceof Error?this._protocol._debug&&this._protocol._debug(`Signature verification failed: ${v.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)&&vs(this);let S,x,P=q=>{if(S)return vs(this),S.outbound.seqno=this._protocol._cipher.outSeqno,this._protocol._cipher.free(),this._protocol._cipher=P0(S),this._protocol._packetRW.write=x,S=void 0,x=void 0,this._protocol._onHandshakeComplete(l),!1;this.sessionID||(this.sessionID=E);{let re=Buffer.allocUnsafe(4+f.length);Qt(re,f.length,0),re.set(f,4),f=re}let C=Qr[l.cs.cipher],$=Qr[l.sc.cipher],F=Hr(C.ivLen,this.hashName,f,E,this.sessionID,"A"),v=Hr($.ivLen,this.hashName,f,E,this.sessionID,"B"),b=Hr(C.keyLen,this.hashName,f,E,this.sessionID,"C"),w=Hr($.keyLen,this.hashName,f,E,this.sessionID,"D"),k,N;C.authLen||(k=Kl[l.cs.mac],N=Hr(k.len,this.hashName,f,E,this.sessionID,"E"));let R,ie;$.authLen||(R=Kl[l.sc.mac],ie=Hr(R.len,this.hashName,f,E,this.sessionID,"F"));let j={inbound:{onPayload:this._protocol._onPayload,seqno:this._protocol._decipher.inSeqno,decipherInfo:c?C:$,decipherIV:c?F:v,decipherKey:c?b:w,macInfo:c?k:R,macKey:c?N:ie},outbound:{onWrite:this._protocol._onWrite,seqno:this._protocol._cipher.outSeqno,cipherInfo:c?$:C,cipherIV:c?v:F,cipherKey:c?w:b,macInfo:c?R:k,macKey:c?ie:N}};this._protocol._decipher.free(),S=j,this._protocol._decipher=T0(j);let X={read:void 0,write:void 0};switch(l.cs.compress){case"zlib":c?X.read=new Cs:X.write=new ks(this._protocol);break;case"zlib@openssh.com":if(this._protocol._authenticated){c?X.read=new Cs:X.write=new ks(this._protocol);break}default:c?X.read=new Vl:X.write=new zl(this._protocol)}switch(l.sc.compress){case"zlib":c?X.write=new ks(this._protocol):X.read=new Cs;break;case"zlib@openssh.com":if(this._protocol._authenticated){c?X.write=new ks(this._protocol):X.read=new Cs;break}default:c?X.write=new zl(this._protocol):X.read=new Vl}return this._protocol._packetRW.read.cleanup(),this._protocol._packetRW.write.cleanup(),this._protocol._packetRW.read=X.read,x=X.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,q?!1:P()};if((c||a)&&(this.finish=P),!c)return P(a)}start(){if(!this._protocol._server){if(this._protocol._debug){let u;this.type==="group"?u="KEXDH_INIT":u="KEXECDH_INIT",this._protocol._debug(`Outbound: Sending ${u}`)}let a=this.getPublicKey(),c=this._protocol._packetRW.write.allocStartKEX,l=this._protocol._packetRW.write.alloc(5+a.length,!0);l[c]=mt.KEXDH_INIT,Qt(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,u=a.length;for(;a[l]===0;)++l,--u;return a[l]&128?(c=Buffer.allocUnsafe(1+u),c[0]=0,a.copy(c,1,l),c):(u!==a.length&&(c=Buffer.allocUnsafe(u),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!==mt.KEXDH_INIT)return je(this._protocol,`Received packet ${c} instead of ${mt.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 u=this._protocol._hostKeys[this.negotiated.serverHostKey];Array.isArray(u)&&(u=u[0]),this._hostKey=u,this.finish()}else{if(c!==mt.KEXDH_REPLY)return je(this._protocol,`Received packet ${c} instead of ${mt.KEXDH_REPLY}`,"handshake",Ye.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH Reply"),Ge.init(a,1);let l,u,f;if((l=Ge.readString())===void 0||(u=Ge.readString())===void 0||(f=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=u,this._sig=f;let p=!1,y;if(this._protocol._hostVerifier===void 0?(y=!0,this._protocol._debug&&this._protocol._debug("Host accepted by default (no verification)")):y=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():vs(this)}}),y===void 0){++this._step;return}if(p=!0,y===!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,vs(this)}++this._step;break;case 2:return c!==mt.NEWKEYS?je(this._protocol,`Received packet ${c} instead of ${mt.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=N0("x25519"))}getPublicKey(){return this.generateKeys(),this._keys.publicKey.export({type:"spki",format:"der"}).slice(-32)}convertPublicKey(a){let c,l=0,u=a.length;for(;a[l]===0;)++l,--u;return a.length===32||u!==a.length&&(c=Buffer.allocUnsafe(u),a.copy(c,0,l),a=c),a}computeSecret(a){this.generateKeys();try{let c=new Ql.Writer;return c.startSequence(),c.startSequence(),c.writeOID("1.3.101.110"),c.endSequence(),c.startSequence(Ql.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(v0({privateKey:this._keys.privateKey,publicKey:k0({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=C0(this.curveName),this._public=this._dh.generateKeys())}}class i extends t{constructor(a,...c){super(...c),this.type="groupex",this.hashName=a,this._prime=null,this._generator=null,this._minBits=$0,this._prefBits=W0(this.negotiated),this._protocol._compatFlags&wa.BUG_DHGEX_LARGE&&(this._prefBits=Math.min(this._prefBits,4096)),this._maxBits=F0}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]=mt.KEXDH_GEX_REQUEST,Qt(c,this._minBits,++a),Qt(c,this._prefBits,a+=4),Qt(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=w0(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!==mt.KEXDH_GEX_REQUEST?je(this._protocol,`Received packet ${c} instead of `+mt.KEXDH_GEX_REQUEST,"handshake",Ye.KEY_EXCHANGE_FAILED):je(this._protocol,"Group exchange not implemented for server","handshake",Ye.KEY_EXCHANGE_FAILED);if(c!==mt.KEXDH_GEX_GROUP)return je(this._protocol,`Received packet ${c} instead of ${mt.KEXDH_GEX_GROUP}`,"handshake",Ye.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Group"),Ge.init(a,1);let l,u;if((l=Ge.readString())===void 0||(u=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,u),this.generateKeys();let f=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+f.length,!0);p[h]=mt.KEXDH_GEX_INIT,Qt(p,f.length,++h),p.set(f,h+=4),this._protocol._cipher.encrypt(this._protocol._packetRW.write.finalize(p,!0)),++this._step;break}case 2:if(this._protocol._server)return c!==mt.KEXDH_GEX_INIT?je(this._protocol,`Received packet ${c} instead of ${mt.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!==mt.KEXDH_GEX_REPLY)return je(this._protocol,`Received packet ${c} instead of ${mt.KEXDH_GEX_REPLY}`,"handshake",Ye.KEY_EXCHANGE_FAILED);this._protocol._debug&&this._protocol._debug("Received DH GEX Reply"),this._step=1,a[0]=mt.KEXDH_REPLY,this.parse=t.prototype.parse,this.parse(a)}}}class s 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]=mt.KEXDH_INIT,Qt(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=I0(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(!R0)break;return new e("sha256",...a);case"ecdh-sha2-nistp256":return new r("prime256v1","sha256",...a);case"ecdh-sha2-nistp384":return new r("secp384r1","sha384",...a);case"ecdh-sha2-nistp521":return new r("secp521r1","sha512",...a);case"diffie-hellman-group1-sha1":return new s("modp2","sha1",...a);case"diffie-hellman-group14-sha1":return new s("modp14","sha1",...a);case"diffie-hellman-group14-sha256":return new s("modp14","sha256",...a);case"diffie-hellman-group15-sha512":return new s("modp15","sha512",...a);case"diffie-hellman-group16-sha512":return new s("modp16","sha512",...a);case"diffie-hellman-group17-sha512":return new s("modp17","sha512",...a);case"diffie-hellman-group18-sha512":return new s("modp18","sha512",...a);case"diffie-hellman-group-exchange-sha1":return new i("sha1",...a);case"diffie-hellman-group-exchange-sha256":return new i("sha256",...a)}throw new Error(`Unsupported key exchange algorithm: ${c}`)}throw new Error(`Invalid key exchange type: ${c}`)}})(),Sa=(()=>{let n=["kex","serverHostKey",["cs","cipher"],["sc","cipher"],["cs","mac"],["sc","mac"],["cs","compress"],["sc","compress"],["cs","lang"],["sc","lang"]];return class{constructor(e){if(typeof e!="object"||e===null)throw new TypeError("Argument must be an object");let r={kex:void 0,serverHostKey:void 0,cs:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0},sc:{cipher:void 0,mac:void 0,compress:void 0,lang:void 0},all:void 0},i=0;for(let a of n){let c,l,u,f;if(typeof a=="string")c=r,l=e[a],u=f=a;else{let p=a[0];c=r[p],f=a[1],l=e[p][f],u=`${p}.${f}`}let h={array:void 0,buffer:void 0};if(Buffer.isBuffer(l))h.array=(""+l).split(","),h.buffer=l,i+=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 \`${u}\` type: ${typeof l}`);i+=4+h.buffer.length}c[f]=h}let s=Buffer.allocUnsafe(i);r.all=s;let o=0;for(let a of n){let c;typeof a=="string"?c=r[a].buffer:c=r[a[0]][a[1]].buffer,o=Qt(s,c.length,o),s.set(c,o),o+=c.length}this.totalSize=i,this.lists=r}copyAllTo(e,r){let i=this.lists.all;if(typeof r!="number")throw new TypeError(`Invalid offset value: ${typeof r}`);if(e.length-r<i.length)throw new Error("Insufficient space to copy list");return e.set(i,r),i.length}}})(),vn=(()=>{let n=Buffer.allocUnsafe(4);return(t,e)=>{Qt(n,e.length,0),t.update(n),t.update(e)}})();function Hr(n,t,e,r,i,s){let o;if(n){let a=xa(t).update(e).update(r).update(s).update(i).digest();for(;a.length<n;){let c=xa(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 D0(a.buffer,a.byteOffset,n)}else o=H0;return o}function jl(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 mt.IGNORE:case mt.UNIMPLEMENTED:case mt.DEBUG:return Fr||(Fr=bs()),Fr[e](this,t)}switch(e){case mt.DISCONNECT:return Fr||(Fr=bs()),Fr[e](this,t);case mt.KEXINIT:return n.firstPacket?(n.firstPacket=!1,Yl(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 W0(n){let t=Qr[n.cs.cipher],e=Qr[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 vs(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]=mt.NEWKEYS,n._protocol._cipher.encrypt(n._protocol._packetRW.write.finalize(e,!0)),n._sentNEWKEYS=!0,n._protocol._strictMode&&(n._protocol._cipher.outSeqno=0)}}Xl.exports={KexInit:Sa,kexinit:Gl,onKEXPayload:jl,DEFAULT_KEXINIT_CLIENT:new Sa({kex:Wl.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),serverHostKey:ql,cs:{cipher:xs,mac:ws,compress:Is,lang:[]},sc:{cipher:xs,mac:ws,compress:Is,lang:[]}}),DEFAULT_KEXINIT_SERVER:new Sa({kex:Wl.concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:ql,cs:{cipher:xs,mac:ws,compress:Is,lang:[]},sc:{cipher:xs,mac:ws,compress:Is,lang:[]}}),HANDLERS:{[mt.KEXINIT]:Yl}}});var Jl=lt((AE,q0)=>{q0.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 va=lt((yE,fu)=>{"use strict";var{inspect:iu}=require("util"),{bindingAvailable:K0,NullCipher:V0,NullDecipher:z0}=Gn(),{COMPAT_CHECKS:G0,DISCONNECT_REASON:su,eddsaSupported:Y0,MESSAGE:Ie,SIGNALS:Zl,TERMINAL_MODE:Ca}=Un(),{DEFAULT_KEXINIT_CLIENT:j0,DEFAULT_KEXINIT_SERVER:X0,KexInit:eu,kexinit:ou,onKEXPayload:J0}=Ss(),{parseKey:tu}=Xn(),Z0=bs(),{bufferCopy:Ns,bufferFill:em,bufferSlice:au,convertSignature:nu,sendPacket:Ce,writeUInt32BE:O}=En(),{PacketReader:tm,PacketWriter:nm,ZlibPacketReader:cu,ZlibPacketWriter:lu}=Ea(),rm=Jl().version,im=new Map(Object.values(su).map(n=>[n,1])),uu=Buffer.from(`SSH-2.0-ssh2js${rm}`),sm=Buffer.from(`${uu}\r
8
+ `),om=8192,am=1024,ru=Buffer.from([Ie.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]),cm=Buffer.from([Ca.TTY_OP_END]);function Ia(){}var ka=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 i=t.debug;this._debug=typeof i=="function"?p=>{i(p)}:void 0;let s=t.onHeader;this._onHeader=typeof s=="function"?(...p)=>{s(...p)}:Ia;let o=t.onPacket;this._onPacket=typeof o=="function"?()=>{o()}:Ia;let a=t.onHandshakeComplete;typeof a!="function"&&(a=Ia);let c;this._onHandshakeComplete=(...p)=>{this._debug&&this._debug("Handshake completed"),c===void 0?c=!0:c=!1;let y=this._queue;if(y){this._queue=void 0,this._debug&&this._debug(`Draining outbound queue (${y.length}) ...`);for(let E=0;E<y.length;++E){let S=y[E],x=this._packetRW.write.finalize(S);if(x===S){let P=this._cipher.allocPacket(S.length);P.set(S,5),x=P}Ce(this,x)}this._debug&&this._debug("... finished draining outbound queue")}c&&this._server&&this._kex.remoteExtInfoEnabled&&mm(this),a(...p)},this._queue=void 0;let l=t.messageHandlers;typeof l=="object"&&l!==null?this._handlers=l:this._handlers={},this._onPayload=dm.bind(this),this._server=!!t.server,this._banner=void 0;let u;if(this._server){if(typeof t.hostKeys!="object"||t.hostKeys===null)throw new Error("Missing server host key(s)");this._hostKeys=t.hostKeys,typeof t.greeting=="string"&&t.greeting.length&&(u=t.greeting.slice(-2)===`\r
9
9
  `?t.greeting:`${t.greeting}\r
10
10
  `),typeof t.banner=="string"&&t.banner.length&&(this._banner=t.banner.slice(-2)===`\r
11
11
  `?t.banner:`${t.banner}\r
12
- `)}else this._hostKeys=void 0;let f=t.offer;typeof f!="object"||f===null?f=this._server?Y0:G0:f.constructor!==Jl&&(this._server?f.kex=f.kex.concat(["kex-strict-s-v00@openssh.com"]):f.kex=f.kex.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),f=new Jl(f)),this._kex=void 0,this._strictMode=void 0,this._kexinit=void 0,this._offer=f,this._cipher=new q0(0,this._onWrite),this._decipher=void 0,this._skipNextInboundPacket=!1,this._packetRW={read:new Z0,write:new em(this)},this._hostVerifier=!this._server&&typeof t.hostVerifier=="function"?t.hostVerifier:void 0,this._parse=cm,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=cu,h=rm;this._compatFlags=0,this._debug&&(W0?this._debug("Custom crypto binding available"):this._debug("Custom crypto binding not available")),this._debug&&this._debug(`Local ident: ${nu(this._identRaw.toString())}`),this.start=()=>{this.start=void 0,u&&this._onWrite(u),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;nm.has(t)||(t=ru.PROTOCOL_ERROR),s[r]=Ie.DISCONNECT,O(s,t,++r),s.fill(0,r+=4,i),this._debug&&this._debug(`Outbound: Sending DISCONNECT (${t})`),Ce(this,this._packetRW.write.finalize(s,!0),!0)}ping(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(tu.length);e.set(tu,t),this._debug&&this._debug("Outbound: Sending ping (GLOBAL_REQUEST: keepalive@openssh.com)"),Ce(this,this._packetRW.write.finalize(e))}rekey(){this._kexinit===void 0?(this._debug&&this._debug("Outbound: Initiated explicit rekey"),this._queue=[],iu(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]=Ie.REQUEST_SUCCESS,r.set(t,++e)):(r=this._packetRW.write.alloc(1),r[e]=Ie.REQUEST_SUCCESS),this._debug&&this._debug("Outbound: Sending REQUEST_SUCCESS"),Ce(this,this._packetRW.write.finalize(r))}requestFailure(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(1);e[t]=Ie.REQUEST_FAILURE,this._debug&&this._debug("Outbound: Sending REQUEST_FAILURE"),Ce(this,this._packetRW.write.finalize(e))}channelSuccess(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Ie.CHANNEL_SUCCESS,O(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_SUCCESS (r:${t})`),Ce(this,this._packetRW.write.finalize(r))}channelFailure(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Ie.CHANNEL_FAILURE,O(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_FAILURE (r:${t})`),Ce(this,this._packetRW.write.finalize(r))}channelEOF(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Ie.CHANNEL_EOF,O(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_EOF (r:${t})`),Ce(this,this._packetRW.write.finalize(r))}channelClose(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Ie.CHANNEL_CLOSE,O(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_CLOSE (r:${t})`),Ce(this,this._packetRW.write.finalize(r))}channelWindowAdjust(t,e){let r=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(9);s[r]=Ie.CHANNEL_WINDOW_ADJUST,O(s,t,++r),O(s,e,r+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_WINDOW_ADJUST (r:${t}, ${e})`),Ce(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]=Ie.CHANNEL_DATA,O(o,t,++i),O(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})`),Ce(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]=Ie.CHANNEL_EXTENDED_DATA,O(a,t,++o),O(a,r,o+=4),O(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})`),Ce(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]=Ie.CHANNEL_OPEN_CONFIRMATION,O(o,t,++i),O(o,e,i+=4),O(o,r,i+=4),O(o,s,i+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_CONFIRMATION (r:${t}, l:${e})`),Ce(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]=Ie.CHANNEL_OPEN_FAILURE,O(o,t,++i),O(o,e,i+=4),O(o,s,i+=4),i+=4,s&&(o.utf8Write(r,i,s),i+=s),O(o,0,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_FAILURE (r:${t})`),Ce(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]=Ie.SERVICE_REQUEST,O(s,e,++r),s.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_REQUEST (${t})`),Ce(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]=Ie.USERAUTH_REQUEST,O(c,s,++a),c.utf8Write(t,a+=4,s),O(c,14,a+=s),c.utf8Write("ssh-connection",a+=4,14),O(c,8,a+=14),c.utf8Write("password",a+=4,8),c[a+=8]=r?1:0,O(c,i,++a),Buffer.isBuffer(e)?vs(e,c,0,i,a+=4):c.utf8Write(e,a+=4,i),r?(O(c,o,a+=i),Buffer.isBuffer(r)?vs(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"),Ce(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=Zl(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,u=l.length,f=(s?4+u:0)+1+4+o+4+14+4+9+1+4+a+4+c,h,p;if(s?(h=Buffer.allocUnsafe(f),p=0,O(h,u,p),h.set(l,p+=4),p+=u):(h=this._packetRW.write.alloc(f),p=this._packetRW.write.allocStart),h[p]=Ie.USERAUTH_REQUEST,O(h,o,++p),h.utf8Write(t,p+=4,o),O(h,14,p+=o),h.utf8Write("ssh-connection",p+=4,14),O(h,9,p+=14),h.utf8Write("publickey",p+=4,9),h[p+=9]=s?1:0,O(h,a,++p),h.utf8Write(r,p+=4,a),O(h,c,p+=a),h.set(e,p+=4),!s){this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey -- check)"),Ce(this,this._packetRW.write.finalize(h));return}s(h,y=>{if(y=eu(y,i),y===!1)throw new Error("Error while converting handshake signature");let E=y.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]=Ie.USERAUTH_REQUEST,O(h,o,++p),h.utf8Write(t,p+=4,o),O(h,14,p+=o),h.utf8Write("ssh-connection",p+=4,14),O(h,9,p+=14),h.utf8Write("publickey",p+=4,9),h[p+=9]=1,O(h,a,++p),h.utf8Write(r,p+=4,a),O(h,c,p+=a),h.set(e,p+=4),O(h,4+a+4+E,p+=c),O(h,a,p+=4),h.utf8Write(r,p+=4,a),O(h,E,p+=a),h.set(y,p+=4),this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey)"),Ce(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=Zl(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),u=e.length,f=this._kex.sessionID,h=f.length,p=Buffer.byteLength(r),y=Buffer.byteLength(s),E=Buffer.allocUnsafe(4+h+1+4+c+4+14+4+9+4+l+4+u+4+p+4+y),S=0;O(E,h,S),E.set(f,S+=4),E[S+=h]=Ie.USERAUTH_REQUEST,O(E,c,++S),E.utf8Write(t,S+=4,c),O(E,14,S+=c),E.utf8Write("ssh-connection",S+=4,14),O(E,9,S+=14),E.utf8Write("hostbased",S+=4,9),O(E,l,S+=9),E.utf8Write(i,S+=4,l),O(E,u,S+=l),E.set(e,S+=4),O(E,p,S+=u),E.utf8Write(r,S+=4,p),O(E,y,S+=p),E.utf8Write(s,S+=4,y),o(E,x=>{if(x=eu(x,a),!x)throw new Error("Error while converting handshake signature");let P=x.length,q=E.length-h-4;S=this._packetRW.write.allocStart;let C=this._packetRW.write.alloc(q+4+4+l+4+P);vs(E,C,4+h,E.length,S),O(C,4+l+4+P,S+=q),O(C,l,S+=4),C.utf8Write(i,S+=4,l),O(C,P,S+=l),C.set(x,S+=4),this._authsQueue.push("hostbased"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (hostbased)"),Ce(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]=Ie.USERAUTH_REQUEST,O(s,e,++r),s.utf8Write(t,r+=4,e),O(s,14,r+=e),s.utf8Write("ssh-connection",r+=4,14),O(s,20,r+=14),s.utf8Write("keyboard-interactive",r+=4,20),O(s,0,r+=20),O(s,0,r+=4),this._authsQueue.push("keyboard-interactive"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (keyboard-interactive)"),Ce(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]=Ie.USERAUTH_REQUEST,O(s,e,++r),s.utf8Write(t,r+=4,e),O(s,14,r+=e),s.utf8Write("ssh-connection",r+=4,14),O(s,4,r+=14),s.utf8Write("none",r+=4,4),this._authsQueue.push("none"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (none)"),Ce(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]=Ie.USERAUTH_INFO_RESPONSE,t){O(i,t.length,++s),s+=4;for(let o=0;o<t.length;++o){let a=r[o];O(i,a,s),s+=4,a&&(i.utf8Write(t[o],s,a),s+=a)}}else O(i,0,++s);this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_RESPONSE"),Ce(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]=Ie.GLOBAL_REQUEST,O(o,13,++i),o.utf8Write("tcpip-forward",i+=4,13),o[i+=13]=r===void 0||r===!0?1:0,O(o,s,++i),o.utf8Write(t,i+=4,s),O(o,e,i+=s),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (tcpip-forward)"),Ce(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]=Ie.GLOBAL_REQUEST,O(o,20,++i),o.utf8Write("cancel-tcpip-forward",i+=4,20),o[i+=20]=r===void 0||r===!0?1:0,O(o,s,++i),o.utf8Write(t,i+=4,s),O(o,e,i+=s),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-tcpip-forward)"),Ce(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]=Ie.GLOBAL_REQUEST,O(i,31,++s),i.utf8Write("streamlocal-forward@openssh.com",s+=4,31),i[s+=31]=e===void 0||e===!0?1:0,O(i,r,++s),i.utf8Write(t,s+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (streamlocal-forward@openssh.com)"),Ce(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]=Ie.GLOBAL_REQUEST,O(i,38,++s),i.utf8Write("cancel-streamlocal-forward@openssh.com",s+=4,38),i[s+=38]=e===void 0||e===!0?1:0,O(i,r,++s),i.utf8Write(t,s+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-streamlocal-forward@openssh.com)"),Ce(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]=Ie.CHANNEL_OPEN,O(c,12,++a),c.utf8Write("direct-tcpip",a+=4,12),O(c,t,a+=12),O(c,e,a+=4),O(c,r,a+=4),O(c,o,a+=4),c.utf8Write(s.dstIP,a+=4,o),O(c,s.dstPort,a+=o),O(c,i,a+=4),c.utf8Write(s.srcIP,a+=4,i),O(c,s.srcPort,a+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-tcpip)`),Ce(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]=Ie.CHANNEL_OPEN,O(a,30,++o),a.utf8Write("direct-streamlocal@openssh.com",o+=4,30),O(a,t,o+=30),O(a,e,o+=4),O(a,r,o+=4),O(a,i,o+=4),a.utf8Write(s.socketPath,o+=4,i),J0(a,0,o+=i,o+8),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-streamlocal@openssh.com)`),Ce(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]=Ie.GLOBAL_REQUEST,O(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)"),Ce(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]=Ie.CHANNEL_OPEN,O(i,7,++s),i.utf8Write("session",s+=4,7),O(i,t,s+=7),O(i,e,s+=4),O(i,r,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, session)`),Ce(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]=Ie.CHANNEL_REQUEST,O(a,t,++o),O(a,13,o+=4),a.utf8Write("window-change",o+=4,13),a[o+=13]=0,O(a,r,++o),O(a,e,o+=4),O(a,i,o+=4),O(a,s,o+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, window-change)`),Ce(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=dm(a)),(!a||!a.length)&&(a=om);let l=o.length,u=a.length,f=this._packetRW.write.allocStart,h=this._packetRW.write.alloc(21+l+4+4+4+4+4+u);if(h[f]=Ie.CHANNEL_REQUEST,O(h,t,++f),O(h,7,f+=4),h.utf8Write("pty-req",f+=4,7),h[f+=7]=c===void 0||c===!0?1:0,O(h,l,++f),h.utf8Write(o,f+=4,l),O(h,r,f+=l),O(h,e,f+=4),O(h,i,f+=4),O(h,s,f+=4),O(h,u,f+=4),f+=4,Array.isArray(a))for(let p=0;p<u;++p)h[f++]=a[p];else Buffer.isBuffer(a)&&h.set(a,f);this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, pty-req)`),Ce(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]=Ie.CHANNEL_REQUEST,O(s,t,++r),O(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)`),Ce(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]=Ie.CHANNEL_REQUEST,O(a,t,++o),O(a,4,o+=4),a.utf8Write("exec",o+=4,4),a[o+=4]=r===void 0||r===!0?1:0,O(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})`),Ce(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)),Xl[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]=Ie.CHANNEL_REQUEST,O(o,t,++i),O(o,6,i+=4),o.utf8Write("signal",i+=4,6),o[i+=6]=0,O(o,s,++i),o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, signal: ${e})`),Ce(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]=Ie.CHANNEL_REQUEST,O(l,t,++c),O(l,3,c+=4),l.utf8Write("env",c+=4,3),l[c+=3]=s===void 0||s===!0?1:0,O(l,i,++c),l.utf8Write(e,c+=4,i),O(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})`),Ce(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),u=this._packetRW.write.allocStart,f=this._packetRW.write.alloc(22+a+4+l+4);f[u]=Ie.CHANNEL_REQUEST,O(f,t,++u),O(f,7,u+=4),f.utf8Write("x11-req",u+=4,7),f[u+=7]=r===void 0||r===!0?1:0,f[++u]=e.single?1:0,O(f,a,++u),o?f.set(s,u+=4):f.utf8Write(s,u+=4,a),O(f,l,u+=a),c?f.set(i,u+=4):f.latin1Write(i,u+=4,l),O(f,e.screen||0,u+=l),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, x11-req)`),Ce(this,this._packetRW.write.finalize(f))}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]=Ie.CHANNEL_REQUEST,O(o,t,++i),O(o,9,i+=4),o.utf8Write("subsystem",i+=4,9),o[i+=9]=r===void 0||r===!0?1:0,O(o,s,++i),o.utf8Write(e,i+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, subsystem: ${e})`),Ce(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]=Ie.CHANNEL_REQUEST,O(s,t,++r),O(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)`),Ce(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]=Ie.GLOBAL_REQUEST,O(i,29,++s),i.utf8Write("hostkeys-prove-00@openssh.com",s+=4,29),i[s+=29]=1,++s;for(let o of r)O(i,o.length,s),vs(o,i,0,o.length,s+=4),s+=o.length;this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (hostkeys-prove-00@openssh.com)"),Ce(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]=Ie.SERVICE_ACCEPT,O(s,e,++r),s.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_ACCEPT (${t})`),Ce(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]=Ie.USERAUTH_BANNER,O(a,o,++r),a.utf8Write(i,r+=4,o),O(a,0,r+=o),this._debug&&this._debug("Outbound: Sending USERAUTH_BANNER"),Ce(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]=Ie.CHANNEL_OPEN,O(c,15,++a),c.utf8Write("forwarded-tcpip",a+=4,15),O(c,t,a+=15),O(c,e,a+=4),O(c,r,a+=4),O(c,i,a+=4),c.utf8Write(s.boundAddr,a+=4,i),O(c,s.boundPort,a+=i),O(c,o,a+=4),c.utf8Write(s.remoteAddr,a+=4,o),O(c,s.remotePort,a+=o),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-tcpip)`),Ce(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]=Ie.CHANNEL_OPEN,O(a,3,++o),a.utf8Write("x11",o+=4,3),O(a,t,o+=3),O(a,e,o+=4),O(a,r,o+=4),O(a,i,o+=4),a.utf8Write(s.originAddr,o+=4,i),O(a,s.originPort,o+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, x11)`),Ce(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]=Ie.CHANNEL_OPEN,O(i,22,++s),i.utf8Write("auth-agent@openssh.com",s+=4,22),O(i,t,s+=22),O(i,e,s+=4),O(i,r,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, auth-agent@openssh.com)`),Ce(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]=Ie.CHANNEL_OPEN,O(a,33,++o),a.utf8Write("forwarded-streamlocal@openssh.com",o+=4,33),O(a,t,o+=33),O(a,e,o+=4),O(a,r,o+=4),O(a,i,o+=4),a.utf8Write(s.socketPath,o+=4,i),O(a,0,o+=i),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-streamlocal@openssh.com)`),Ce(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]=Ie.CHANNEL_REQUEST,O(s,t,++r),O(s,11,r+=4),s.utf8Write("exit-status",r+=4,11),s[r+=11]=0,O(s,e,++r),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-status: ${e})`),Ce(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)),Xl[o]!==1)throw new Error(`Invalid signal: ${i}`);let a=Buffer.byteLength(o),c=s?Buffer.byteLength(s):0,l=this._packetRW.write.allocStart,u=this._packetRW.write.alloc(25+a+1+4+c+4);u[l]=Ie.CHANNEL_REQUEST,O(u,t,++l),O(u,11,l+=4),u.utf8Write("exit-signal",l+=4,11),u[l+=11]=0,O(u,a,++l),u.utf8Write(o,l+=4,a),u[l+=a]=r?1:0,O(u,c,++l),l+=4,c&&(u.utf8Write(s,l,c),l+=c),O(u,0,l),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-signal: ${e})`),Ce(this,this._packetRW.write.finalize(u))}authFailure(t,e){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0)throw new Error("No auth in progress");let r;if(typeof t=="boolean"&&(e=t,t=void 0),t){r=[];for(let a=0;a<t.length;++a)t[a].toLowerCase()!=="none"&&r.push(t[a]);r=r.join(",")}else r="";let s=r.length,i=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+s+1);o[i]=Ie.USERAUTH_FAILURE,O(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"),Ce(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]=Ie.USERAUTH_SUCCESS,this._authsQueue.shift(),this._authenticated=!0,this._debug&&this._debug("Outbound: Sending USERAUTH_SUCCESS"),Ce(this,this._packetRW.write.finalize(e)),this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.read=new ou),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.write=new au(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]=Ie.USERAUTH_PK_OK,O(o,r,++i),o.utf8Write(t,i+=4,r),O(o,s,i+=r),o.set(e,i+=4),this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_PK_OK"),Ce(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]=Ie.USERAUTH_PASSWD_CHANGEREQ,O(s,e,++r),s.utf8Write(t,r+=4,e),O(s,0,r+=e),this._debug&&this._debug("Outbound: Sending USERAUTH_PASSWD_CHANGEREQ"),Ce(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]=Ie.USERAUTH_INFO_REQUEST,O(c,i,++a),a+=4,t&&(c.utf8Write(t,a,i),a+=i),O(c,o,a),a+=4,e&&(c.utf8Write(e,a,o),a+=o),O(c,0,a),O(c,r.length,a+=4),a+=4;for(let l=0;l<r.length;++l){let u=r[l],f=Buffer.byteLength(u.prompt);O(c,f,a),a+=4,f&&(c.utf8Write(u.prompt,a,f),a+=f),c[a++]=u.echo?1:0}this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_REQUEST"),Ce(this,this._packetRW.write.finalize(c))}},am=/^SSH-(2\.0|1\.99)-([^ ]+)(?: (.*))?$/;function cm(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,u=0;for(;t<r.length;++t){let f=r[t];if(f===13){c=!0;continue}if(f===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),y=am.exec(p);if(!y)throw new Error("Invalid identification string");let E={greeting:o===i?"":h.slice(0,o-i),identRaw:p,versions:{protocol:y[1],software:y[2]},comments:y[3]};return this._remoteIdentRaw=Buffer.from(p),this._debug&&this._debug(`Remote ident: ${nu(p)}`),this._compatFlags=fm(E),this._buffer=void 0,this._decipher=new K0(0,j0.bind(this,{firstPacket:!0})),this._parse=lm,this._onHeader(E),this._destruct?(iu(this),t+1-s):e}if(this._server)throw new Error("Greetings from clients not permitted");if(++u>sm)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>=im)throw new Error("Header line too long")}a=t}return this._buffer||(this._buffer=su(r,i)),t-s}function lm(n,t,e){return this._decipher.decrypt(n,t,e)}function um(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===Ie.USERAUTH_SUCCESS&&!this._server&&!this._authenticated&&(this._authenticated=!0,this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.write=new au(this)),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.read=new ou));let e=X0[t];if(e===void 0){this._debug&&this._debug(`Inbound: Unsupported message type: ${t}`);return}return e(this,n)}function fm(n){let t=n.versions.software,e=0;for(let r of V0)typeof r[0]=="string"?t===r[0]&&(e|=r[1]):r[0].test(t)&&(e|=r[1]);return e}function dm(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=wa[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++]=wa.TTY_OP_END,r<e.length?su(e,0,r):e}function hm(n){let t="ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss";z0&&(t=`ssh-ed25519,${t}`);let e=Buffer.byteLength(t),r=n._packetRW.write.allocStart,s=n._packetRW.write.alloc(28+e);s[r]=Ie.EXT_INFO,O(s,1,++r),O(s,15,r+=4),s.utf8Write("server-sig-algs",r+=4,15),O(s,e,r+=15),s.utf8Write(t,r+=4,e),n._debug&&n._debug("Outbound: Sending EXT_INFO"),Ce(n,n._packetRW.write.finalize(s))}lu.exports=Ia});var mu=lt(ki=>{"use strict";var Ns=require("assert"),{inspect:pm}=require("util");function uu(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 fu(n,t){if(Ns(typeof t=="string","`thing` has to be of type string"),Array.isArray(n)){let e=n.length;return Ns(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)}`}ki.ERR_INTERNAL_ASSERTION=class hu extends Error{constructor(t){super(),Error.captureStackTrace(this,hu);let e=`This is caused by either a bug in ssh2 or incorrect usage of ssh2 internals.
12
+ `)}else this._hostKeys=void 0;let f=t.offer;typeof f!="object"||f===null?f=this._server?X0:j0:f.constructor!==eu&&(this._server?f.kex=f.kex.concat(["kex-strict-s-v00@openssh.com"]):f.kex=f.kex.concat(["ext-info-c","kex-strict-c-v00@openssh.com"]),f=new eu(f)),this._kex=void 0,this._strictMode=void 0,this._kexinit=void 0,this._offer=f,this._cipher=new V0(0,this._onWrite),this._decipher=void 0,this._skipNextInboundPacket=!1,this._packetRW={read:new tm,write:new nm(this)},this._hostVerifier=!this._server&&typeof t.hostVerifier=="function"?t.hostVerifier:void 0,this._parse=um,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=uu,h=sm;this._compatFlags=0,this._debug&&(K0?this._debug("Custom crypto binding available"):this._debug("Custom crypto binding not available")),this._debug&&this._debug(`Local ident: ${iu(this._identRaw.toString())}`),this.start=()=>{this.start=void 0,u&&this._onWrite(u),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,i=this._packetRW.write.alloc(13,!0),s=r+13;im.has(t)||(t=su.PROTOCOL_ERROR),i[r]=Ie.DISCONNECT,O(i,t,++r),i.fill(0,r+=4,s),this._debug&&this._debug(`Outbound: Sending DISCONNECT (${t})`),Ce(this,this._packetRW.write.finalize(i,!0),!0)}ping(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(ru.length);e.set(ru,t),this._debug&&this._debug("Outbound: Sending ping (GLOBAL_REQUEST: keepalive@openssh.com)"),Ce(this,this._packetRW.write.finalize(e))}rekey(){this._kexinit===void 0?(this._debug&&this._debug("Outbound: Initiated explicit rekey"),this._queue=[],ou(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]=Ie.REQUEST_SUCCESS,r.set(t,++e)):(r=this._packetRW.write.alloc(1),r[e]=Ie.REQUEST_SUCCESS),this._debug&&this._debug("Outbound: Sending REQUEST_SUCCESS"),Ce(this,this._packetRW.write.finalize(r))}requestFailure(){let t=this._packetRW.write.allocStart,e=this._packetRW.write.alloc(1);e[t]=Ie.REQUEST_FAILURE,this._debug&&this._debug("Outbound: Sending REQUEST_FAILURE"),Ce(this,this._packetRW.write.finalize(e))}channelSuccess(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Ie.CHANNEL_SUCCESS,O(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_SUCCESS (r:${t})`),Ce(this,this._packetRW.write.finalize(r))}channelFailure(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Ie.CHANNEL_FAILURE,O(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_FAILURE (r:${t})`),Ce(this,this._packetRW.write.finalize(r))}channelEOF(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Ie.CHANNEL_EOF,O(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_EOF (r:${t})`),Ce(this,this._packetRW.write.finalize(r))}channelClose(t){let e=this._packetRW.write.allocStart,r=this._packetRW.write.alloc(5);r[e]=Ie.CHANNEL_CLOSE,O(r,t,++e),this._debug&&this._debug(`Outbound: Sending CHANNEL_CLOSE (r:${t})`),Ce(this,this._packetRW.write.finalize(r))}channelWindowAdjust(t,e){let r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(9);i[r]=Ie.CHANNEL_WINDOW_ADJUST,O(i,t,++r),O(i,e,r+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_WINDOW_ADJUST (r:${t}, ${e})`),Ce(this,this._packetRW.write.finalize(i))}channelData(t,e){let r=Buffer.isBuffer(e),i=r?e.length:Buffer.byteLength(e),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(9+i);o[s]=Ie.CHANNEL_DATA,O(o,t,++s),O(o,i,s+=4),r?o.set(e,s+=4):o.utf8Write(e,s+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_DATA (r:${t}, ${i})`),Ce(this,this._packetRW.write.finalize(o))}channelExtData(t,e,r){let i=Buffer.isBuffer(e),s=i?e.length:Buffer.byteLength(e),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(13+s);a[o]=Ie.CHANNEL_EXTENDED_DATA,O(a,t,++o),O(a,r,o+=4),O(a,s,o+=4),i?a.set(e,o+=4):a.utf8Write(e,o+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_EXTENDED_DATA (r:${t})`),Ce(this,this._packetRW.write.finalize(a))}channelOpenConfirm(t,e,r,i){let s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(17);o[s]=Ie.CHANNEL_OPEN_CONFIRMATION,O(o,t,++s),O(o,e,s+=4),O(o,r,s+=4),O(o,i,s+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_CONFIRMATION (r:${t}, l:${e})`),Ce(this,this._packetRW.write.finalize(o))}channelOpenFail(t,e,r){typeof r!="string"&&(r="");let i=Buffer.byteLength(r),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(13+i+4);o[s]=Ie.CHANNEL_OPEN_FAILURE,O(o,t,++s),O(o,e,s+=4),O(o,i,s+=4),s+=4,i&&(o.utf8Write(r,s,i),s+=i),O(o,0,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN_FAILURE (r:${t})`),Ce(this,this._packetRW.write.finalize(o))}service(t){if(this._server)throw new Error("Client-only method called in server mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e);i[r]=Ie.SERVICE_REQUEST,O(i,e,++r),i.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_REQUEST (${t})`),Ce(this,this._packetRW.write.finalize(i))}authPassword(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(t),s=Buffer.byteLength(e),o=r?Buffer.byteLength(r):0,a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+i+4+14+4+8+1+4+s+(r?4+o:0));c[a]=Ie.USERAUTH_REQUEST,O(c,i,++a),c.utf8Write(t,a+=4,i),O(c,14,a+=i),c.utf8Write("ssh-connection",a+=4,14),O(c,8,a+=14),c.utf8Write("password",a+=4,8),c[a+=8]=r?1:0,O(c,s,++a),Buffer.isBuffer(e)?Ns(e,c,0,s,a+=4):c.utf8Write(e,a+=4,s),r?(O(c,o,a+=s),Buffer.isBuffer(r)?Ns(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"),Ce(this,this._packetRW.write.finalize(c))}authPK(t,e,r,i){if(this._server)throw new Error("Client-only method called in server mode");if(e=tu(e),e instanceof Error)throw new Error("Invalid key");let s=e.type;e=e.getPublicSSH(),typeof r=="function"&&(i=r,r=void 0),r||(r=s);let o=Buffer.byteLength(t),a=Buffer.byteLength(r),c=e.length,l=this._kex.sessionID,u=l.length,f=(i?4+u:0)+1+4+o+4+14+4+9+1+4+a+4+c,h,p;if(i?(h=Buffer.allocUnsafe(f),p=0,O(h,u,p),h.set(l,p+=4),p+=u):(h=this._packetRW.write.alloc(f),p=this._packetRW.write.allocStart),h[p]=Ie.USERAUTH_REQUEST,O(h,o,++p),h.utf8Write(t,p+=4,o),O(h,14,p+=o),h.utf8Write("ssh-connection",p+=4,14),O(h,9,p+=14),h.utf8Write("publickey",p+=4,9),h[p+=9]=i?1:0,O(h,a,++p),h.utf8Write(r,p+=4,a),O(h,c,p+=a),h.set(e,p+=4),!i){this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey -- check)"),Ce(this,this._packetRW.write.finalize(h));return}i(h,y=>{if(y=nu(y,s),y===!1)throw new Error("Error while converting handshake signature");let E=y.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]=Ie.USERAUTH_REQUEST,O(h,o,++p),h.utf8Write(t,p+=4,o),O(h,14,p+=o),h.utf8Write("ssh-connection",p+=4,14),O(h,9,p+=14),h.utf8Write("publickey",p+=4,9),h[p+=9]=1,O(h,a,++p),h.utf8Write(r,p+=4,a),O(h,c,p+=a),h.set(e,p+=4),O(h,4+a+4+E,p+=c),O(h,a,p+=4),h.utf8Write(r,p+=4,a),O(h,E,p+=a),h.set(y,p+=4),this._authsQueue.push("publickey"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (publickey)"),Ce(this,this._packetRW.write.finalize(h))})}authHostbased(t,e,r,i,s,o){if(this._server)throw new Error("Client-only method called in server mode");if(e=tu(e),e instanceof Error)throw new Error("Invalid key");let a=e.type;e=e.getPublicSSH(),typeof s=="function"&&(o=s,s=void 0),s||(s=a);let c=Buffer.byteLength(t),l=Buffer.byteLength(s),u=e.length,f=this._kex.sessionID,h=f.length,p=Buffer.byteLength(r),y=Buffer.byteLength(i),E=Buffer.allocUnsafe(4+h+1+4+c+4+14+4+9+4+l+4+u+4+p+4+y),S=0;O(E,h,S),E.set(f,S+=4),E[S+=h]=Ie.USERAUTH_REQUEST,O(E,c,++S),E.utf8Write(t,S+=4,c),O(E,14,S+=c),E.utf8Write("ssh-connection",S+=4,14),O(E,9,S+=14),E.utf8Write("hostbased",S+=4,9),O(E,l,S+=9),E.utf8Write(s,S+=4,l),O(E,u,S+=l),E.set(e,S+=4),O(E,p,S+=u),E.utf8Write(r,S+=4,p),O(E,y,S+=p),E.utf8Write(i,S+=4,y),o(E,x=>{if(x=nu(x,a),!x)throw new Error("Error while converting handshake signature");let P=x.length,q=E.length-h-4;S=this._packetRW.write.allocStart;let C=this._packetRW.write.alloc(q+4+4+l+4+P);Ns(E,C,4+h,E.length,S),O(C,4+l+4+P,S+=q),O(C,l,S+=4),C.utf8Write(s,S+=4,l),O(C,P,S+=l),C.set(x,S+=4),this._authsQueue.push("hostbased"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (hostbased)"),Ce(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,i=this._packetRW.write.alloc(5+e+4+14+4+20+4+4);i[r]=Ie.USERAUTH_REQUEST,O(i,e,++r),i.utf8Write(t,r+=4,e),O(i,14,r+=e),i.utf8Write("ssh-connection",r+=4,14),O(i,20,r+=14),i.utf8Write("keyboard-interactive",r+=4,20),O(i,0,r+=20),O(i,0,r+=4),this._authsQueue.push("keyboard-interactive"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (keyboard-interactive)"),Ce(this,this._packetRW.write.finalize(i))}authNone(t){if(this._server)throw new Error("Client-only method called in server mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e+4+14+4+4);i[r]=Ie.USERAUTH_REQUEST,O(i,e,++r),i.utf8Write(t,r+=4,e),O(i,14,r+=e),i.utf8Write("ssh-connection",r+=4,14),O(i,4,r+=14),i.utf8Write("none",r+=4,4),this._authsQueue.push("none"),this._debug&&this._debug("Outbound: Sending USERAUTH_REQUEST (none)"),Ce(this,this._packetRW.write.finalize(i))}authInfoRes(t){if(this._server)throw new Error("Client-only method called in server mode");let e=0,r;if(t){r=new Array(t.length);for(let o=0;o<t.length;++o){let a=Buffer.byteLength(t[o]);r[o]=a,e+=4+a}}let i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(5+e);if(s[i]=Ie.USERAUTH_INFO_RESPONSE,t){O(s,t.length,++i),i+=4;for(let o=0;o<t.length;++o){let a=r[o];O(s,a,i),i+=4,a&&(s.utf8Write(t[o],i,a),i+=a)}}else O(s,0,++i);this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_RESPONSE"),Ce(this,this._packetRW.write.finalize(s))}tcpipForward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(t),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(23+i+4);o[s]=Ie.GLOBAL_REQUEST,O(o,13,++s),o.utf8Write("tcpip-forward",s+=4,13),o[s+=13]=r===void 0||r===!0?1:0,O(o,i,++s),o.utf8Write(t,s+=4,i),O(o,e,s+=i),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (tcpip-forward)"),Ce(this,this._packetRW.write.finalize(o))}cancelTcpipForward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(t),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(30+i+4);o[s]=Ie.GLOBAL_REQUEST,O(o,20,++s),o.utf8Write("cancel-tcpip-forward",s+=4,20),o[s+=20]=r===void 0||r===!0?1:0,O(o,i,++s),o.utf8Write(t,s+=4,i),O(o,e,s+=i),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-tcpip-forward)"),Ce(this,this._packetRW.write.finalize(o))}openssh_streamLocalForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(41+r);s[i]=Ie.GLOBAL_REQUEST,O(s,31,++i),s.utf8Write("streamlocal-forward@openssh.com",i+=4,31),s[i+=31]=e===void 0||e===!0?1:0,O(s,r,++i),s.utf8Write(t,i+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (streamlocal-forward@openssh.com)"),Ce(this,this._packetRW.write.finalize(s))}openssh_cancelStreamLocalForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(48+r);s[i]=Ie.GLOBAL_REQUEST,O(s,38,++i),s.utf8Write("cancel-streamlocal-forward@openssh.com",i+=4,38),s[i+=38]=e===void 0||e===!0?1:0,O(s,r,++i),s.utf8Write(t,i+=4,r),this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (cancel-streamlocal-forward@openssh.com)"),Ce(this,this._packetRW.write.finalize(s))}directTcpip(t,e,r,i){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(i.srcIP),o=Buffer.byteLength(i.dstIP),a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(33+s+4+4+o+4);c[a]=Ie.CHANNEL_OPEN,O(c,12,++a),c.utf8Write("direct-tcpip",a+=4,12),O(c,t,a+=12),O(c,e,a+=4),O(c,r,a+=4),O(c,o,a+=4),c.utf8Write(i.dstIP,a+=4,o),O(c,i.dstPort,a+=o),O(c,s,a+=4),c.utf8Write(i.srcIP,a+=4,s),O(c,i.srcPort,a+=s),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-tcpip)`),Ce(this,this._packetRW.write.finalize(c))}openssh_directStreamLocal(t,e,r,i){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(i.socketPath),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(51+s+4+4);a[o]=Ie.CHANNEL_OPEN,O(a,30,++o),a.utf8Write("direct-streamlocal@openssh.com",o+=4,30),O(a,t,o+=30),O(a,e,o+=4),O(a,r,o+=4),O(a,s,o+=4),a.utf8Write(i.socketPath,o+=4,s),em(a,0,o+=s,o+8),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, direct-streamlocal@openssh.com)`),Ce(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]=Ie.GLOBAL_REQUEST,O(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)"),Ce(this,this._packetRW.write.finalize(r))}session(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(24);s[i]=Ie.CHANNEL_OPEN,O(s,7,++i),s.utf8Write("session",i+=4,7),O(s,t,i+=7),O(s,e,i+=4),O(s,r,i+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, session)`),Ce(this,this._packetRW.write.finalize(s))}windowChange(t,e,r,i,s){if(this._server)throw new Error("Client-only method called in server mode");let o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(39);a[o]=Ie.CHANNEL_REQUEST,O(a,t,++o),O(a,13,o+=4),a.utf8Write("window-change",o+=4,13),a[o+=13]=0,O(a,r,++o),O(a,e,o+=4),O(a,s,o+=4),O(a,i,o+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, window-change)`),Ce(this,this._packetRW.write.finalize(a))}pty(t,e,r,i,s,o,a,c){if(this._server)throw new Error("Client-only method called in server mode");(!o||!o.length)&&(o="vt100"),a&&!Buffer.isBuffer(a)&&!Array.isArray(a)&&typeof a=="object"&&a!==null&&(a=pm(a)),(!a||!a.length)&&(a=cm);let l=o.length,u=a.length,f=this._packetRW.write.allocStart,h=this._packetRW.write.alloc(21+l+4+4+4+4+4+u);if(h[f]=Ie.CHANNEL_REQUEST,O(h,t,++f),O(h,7,f+=4),h.utf8Write("pty-req",f+=4,7),h[f+=7]=c===void 0||c===!0?1:0,O(h,l,++f),h.utf8Write(o,f+=4,l),O(h,r,f+=l),O(h,e,f+=4),O(h,s,f+=4),O(h,i,f+=4),O(h,u,f+=4),f+=4,Array.isArray(a))for(let p=0;p<u;++p)h[f++]=a[p];else Buffer.isBuffer(a)&&h.set(a,f);this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, pty-req)`),Ce(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,i=this._packetRW.write.alloc(15);i[r]=Ie.CHANNEL_REQUEST,O(i,t,++r),O(i,5,r+=4),i.utf8Write("shell",r+=4,5),i[r+=5]=e===void 0||e===!0?1:0,this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, shell)`),Ce(this,this._packetRW.write.finalize(i))}exec(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.isBuffer(e),s=i?e.length:Buffer.byteLength(e),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(18+s);a[o]=Ie.CHANNEL_REQUEST,O(a,t,++o),O(a,4,o+=4),a.utf8Write("exec",o+=4,4),a[o+=4]=r===void 0||r===!0?1:0,O(a,s,++o),i?a.set(e,o+=4):a.utf8Write(e,o+=4,s),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exec: ${e})`),Ce(this,this._packetRW.write.finalize(a))}signal(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=e;if(e=e.toUpperCase(),e.slice(0,3)==="SIG"&&(e=e.slice(3)),Zl[e]!==1)throw new Error(`Invalid signal: ${r}`);let i=e.length,s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(20+i);o[s]=Ie.CHANNEL_REQUEST,O(o,t,++s),O(o,6,s+=4),o.utf8Write("signal",s+=4,6),o[s+=6]=0,O(o,i,++s),o.utf8Write(e,s+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, signal: ${e})`),Ce(this,this._packetRW.write.finalize(o))}env(t,e,r,i){if(this._server)throw new Error("Client-only method called in server mode");let s=Buffer.byteLength(e),o=Buffer.isBuffer(r),a=o?r.length:Buffer.byteLength(r),c=this._packetRW.write.allocStart,l=this._packetRW.write.alloc(17+s+4+a);l[c]=Ie.CHANNEL_REQUEST,O(l,t,++c),O(l,3,c+=4),l.utf8Write("env",c+=4,3),l[c+=3]=i===void 0||i===!0?1:0,O(l,s,++c),l.utf8Write(e,c+=4,s),O(l,a,c+=s),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})`),Ce(this,this._packetRW.write.finalize(l))}x11Forward(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let i=e.protocol,s=e.cookie,o=Buffer.isBuffer(i),a=o?i.length:Buffer.byteLength(i),c=Buffer.isBuffer(s),l=c?s.length:Buffer.byteLength(s),u=this._packetRW.write.allocStart,f=this._packetRW.write.alloc(22+a+4+l+4);f[u]=Ie.CHANNEL_REQUEST,O(f,t,++u),O(f,7,u+=4),f.utf8Write("x11-req",u+=4,7),f[u+=7]=r===void 0||r===!0?1:0,f[++u]=e.single?1:0,O(f,a,++u),o?f.set(i,u+=4):f.utf8Write(i,u+=4,a),O(f,l,u+=a),c?f.set(s,u+=4):f.latin1Write(s,u+=4,l),O(f,e.screen||0,u+=l),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, x11-req)`),Ce(this,this._packetRW.write.finalize(f))}subsystem(t,e,r){if(this._server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(e),s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(23+i);o[s]=Ie.CHANNEL_REQUEST,O(o,t,++s),O(o,9,s+=4),o.utf8Write("subsystem",s+=4,9),o[s+=9]=r===void 0||r===!0?1:0,O(o,i,++s),o.utf8Write(e,s+=4,i),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, subsystem: ${e})`),Ce(this,this._packetRW.write.finalize(o))}openssh_agentForward(t,e){if(this._server)throw new Error("Client-only method called in server mode");let r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(36);i[r]=Ie.CHANNEL_REQUEST,O(i,t,++r),O(i,26,r+=4),i.utf8Write("auth-agent-req@openssh.com",r+=4,26),i[r+=26]=e===void 0||e===!0?1:0,this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, auth-agent-req@openssh.com)`),Ce(this,this._packetRW.write.finalize(i))}openssh_hostKeysProve(t){if(this._server)throw new Error("Client-only method called in server mode");let e=0,r=[];for(let o of t){let a=o.getPublicSSH();e+=4+a.length,r.push(a)}let i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(35+e);s[i]=Ie.GLOBAL_REQUEST,O(s,29,++i),s.utf8Write("hostkeys-prove-00@openssh.com",i+=4,29),s[i+=29]=1,++i;for(let o of r)O(s,o.length,i),Ns(o,s,0,o.length,i+=4),i+=o.length;this._debug&&this._debug("Outbound: Sending GLOBAL_REQUEST (hostkeys-prove-00@openssh.com)"),Ce(this,this._packetRW.write.finalize(s))}serviceAccept(t){if(!this._server)throw new Error("Server-only method called in client mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e);if(i[r]=Ie.SERVICE_ACCEPT,O(i,e,++r),i.utf8Write(t,r+=4,e),this._debug&&this._debug(`Outbound: Sending SERVICE_ACCEPT (${t})`),Ce(this,this._packetRW.write.finalize(i)),this._server&&this._banner&&t==="ssh-userauth"){let s=this._banner;this._banner=void 0;let o=Buffer.byteLength(s);r=this._packetRW.write.allocStart;let a=this._packetRW.write.alloc(5+o+4);a[r]=Ie.USERAUTH_BANNER,O(a,o,++r),a.utf8Write(s,r+=4,o),O(a,0,r+=o),this._debug&&this._debug("Outbound: Sending USERAUTH_BANNER"),Ce(this,this._packetRW.write.finalize(a))}}forwardedTcpip(t,e,r,i){if(!this._server)throw new Error("Server-only method called in client mode");let s=Buffer.byteLength(i.boundAddr),o=Buffer.byteLength(i.remoteAddr),a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(36+s+4+4+o+4);c[a]=Ie.CHANNEL_OPEN,O(c,15,++a),c.utf8Write("forwarded-tcpip",a+=4,15),O(c,t,a+=15),O(c,e,a+=4),O(c,r,a+=4),O(c,s,a+=4),c.utf8Write(i.boundAddr,a+=4,s),O(c,i.boundPort,a+=s),O(c,o,a+=4),c.utf8Write(i.remoteAddr,a+=4,o),O(c,i.remotePort,a+=o),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-tcpip)`),Ce(this,this._packetRW.write.finalize(c))}x11(t,e,r,i){if(!this._server)throw new Error("Server-only method called in client mode");let s=Buffer.byteLength(i.originAddr),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(24+s+4);a[o]=Ie.CHANNEL_OPEN,O(a,3,++o),a.utf8Write("x11",o+=4,3),O(a,t,o+=3),O(a,e,o+=4),O(a,r,o+=4),O(a,s,o+=4),a.utf8Write(i.originAddr,o+=4,s),O(a,i.originPort,o+=s),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, x11)`),Ce(this,this._packetRW.write.finalize(a))}openssh_authAgent(t,e,r){if(!this._server)throw new Error("Server-only method called in client mode");let i=this._packetRW.write.allocStart,s=this._packetRW.write.alloc(39);s[i]=Ie.CHANNEL_OPEN,O(s,22,++i),s.utf8Write("auth-agent@openssh.com",i+=4,22),O(s,t,i+=22),O(s,e,i+=4),O(s,r,i+=4),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, auth-agent@openssh.com)`),Ce(this,this._packetRW.write.finalize(s))}openssh_forwardedStreamLocal(t,e,r,i){if(!this._server)throw new Error("Server-only method called in client mode");let s=Buffer.byteLength(i.socketPath),o=this._packetRW.write.allocStart,a=this._packetRW.write.alloc(54+s+4);a[o]=Ie.CHANNEL_OPEN,O(a,33,++o),a.utf8Write("forwarded-streamlocal@openssh.com",o+=4,33),O(a,t,o+=33),O(a,e,o+=4),O(a,r,o+=4),O(a,s,o+=4),a.utf8Write(i.socketPath,o+=4,s),O(a,0,o+=s),this._debug&&this._debug(`Outbound: Sending CHANNEL_OPEN (r:${t}, forwarded-streamlocal@openssh.com)`),Ce(this,this._packetRW.write.finalize(a))}exitStatus(t,e){if(!this._server)throw new Error("Server-only method called in client mode");let r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(25);i[r]=Ie.CHANNEL_REQUEST,O(i,t,++r),O(i,11,r+=4),i.utf8Write("exit-status",r+=4,11),i[r+=11]=0,O(i,e,++r),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-status: ${e})`),Ce(this,this._packetRW.write.finalize(i))}exitSignal(t,e,r,i){if(!this._server)throw new Error("Server-only method called in client mode");let s=e;if(typeof s!="string"||!s)throw new Error(`Invalid signal: ${s}`);let o=e.toUpperCase();if(o.slice(0,3)==="SIG"&&(o=o.slice(3)),Zl[o]!==1)throw new Error(`Invalid signal: ${s}`);let a=Buffer.byteLength(o),c=i?Buffer.byteLength(i):0,l=this._packetRW.write.allocStart,u=this._packetRW.write.alloc(25+a+1+4+c+4);u[l]=Ie.CHANNEL_REQUEST,O(u,t,++l),O(u,11,l+=4),u.utf8Write("exit-signal",l+=4,11),u[l+=11]=0,O(u,a,++l),u.utf8Write(o,l+=4,a),u[l+=a]=r?1:0,O(u,c,++l),l+=4,c&&(u.utf8Write(i,l,c),l+=c),O(u,0,l),this._debug&&this._debug(`Outbound: Sending CHANNEL_REQUEST (r:${t}, exit-signal: ${e})`),Ce(this,this._packetRW.write.finalize(u))}authFailure(t,e){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0)throw new Error("No auth in progress");let r;if(typeof t=="boolean"&&(e=t,t=void 0),t){r=[];for(let a=0;a<t.length;++a)t[a].toLowerCase()!=="none"&&r.push(t[a]);r=r.join(",")}else r="";let i=r.length,s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+i+1);o[s]=Ie.USERAUTH_FAILURE,O(o,i,++s),o.utf8Write(r,s+=4,i),o[s+=i]=e===!0?1:0,this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_FAILURE"),Ce(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]=Ie.USERAUTH_SUCCESS,this._authsQueue.shift(),this._authenticated=!0,this._debug&&this._debug("Outbound: Sending USERAUTH_SUCCESS"),Ce(this,this._packetRW.write.finalize(e)),this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.read=new cu),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.write=new lu(this))}authPKOK(t,e){if(!this._server)throw new Error("Server-only method called in client mode");if(this._authsQueue.length===0||this._authsQueue[0]!=="publickey")throw new Error('"publickey" auth not in progress');let r=Buffer.byteLength(t),i=e.length,s=this._packetRW.write.allocStart,o=this._packetRW.write.alloc(5+r+4+i);o[s]=Ie.USERAUTH_PK_OK,O(o,r,++s),o.utf8Write(t,s+=4,r),O(o,i,s+=r),o.set(e,s+=4),this._authsQueue.shift(),this._debug&&this._debug("Outbound: Sending USERAUTH_PK_OK"),Ce(this,this._packetRW.write.finalize(o))}authPasswdChg(t){if(!this._server)throw new Error("Server-only method called in client mode");let e=Buffer.byteLength(t),r=this._packetRW.write.allocStart,i=this._packetRW.write.alloc(5+e+4);i[r]=Ie.USERAUTH_PASSWD_CHANGEREQ,O(i,e,++r),i.utf8Write(t,r+=4,e),O(i,0,r+=e),this._debug&&this._debug("Outbound: Sending USERAUTH_PASSWD_CHANGEREQ"),Ce(this,this._packetRW.write.finalize(i))}authInfoReq(t,e,r){if(!this._server)throw new Error("Server-only method called in client mode");let i=0,s=t?Buffer.byteLength(t):0,o=e?Buffer.byteLength(e):0;for(let l=0;l<r.length;++l)i+=4+Buffer.byteLength(r[l].prompt)+1;let a=this._packetRW.write.allocStart,c=this._packetRW.write.alloc(5+s+4+o+4+4+i);c[a]=Ie.USERAUTH_INFO_REQUEST,O(c,s,++a),a+=4,t&&(c.utf8Write(t,a,s),a+=s),O(c,o,a),a+=4,e&&(c.utf8Write(e,a,o),a+=o),O(c,0,a),O(c,r.length,a+=4),a+=4;for(let l=0;l<r.length;++l){let u=r[l],f=Buffer.byteLength(u.prompt);O(c,f,a),a+=4,f&&(c.utf8Write(u.prompt,a,f),a+=f),c[a++]=u.echo?1:0}this._debug&&this._debug("Outbound: Sending USERAUTH_INFO_REQUEST"),Ce(this,this._packetRW.write.finalize(c))}},lm=/^SSH-(2\.0|1\.99)-([^ ]+)(?: (.*))?$/;function um(n,t,e){let r,i;this._buffer?(r=Buffer.allocUnsafe(this._buffer.length+(e-t)),r.set(this._buffer,0),t===0?r.set(n,this._buffer.length):r.set(new Uint8Array(n.buffer,n.byteOffset+t,e-t),this._buffer.length),i=this._buffer.length,t=0):(r=n,i=0);let s=t,o=t,a=t,c=!1,l=0,u=0;for(;t<r.length;++t){let f=r[t];if(f===13){c=!0;continue}if(f===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(s,a+1),p=o===s?h:h.slice(o-s),y=lm.exec(p);if(!y)throw new Error("Invalid identification string");let E={greeting:o===s?"":h.slice(0,o-s),identRaw:p,versions:{protocol:y[1],software:y[2]},comments:y[3]};return this._remoteIdentRaw=Buffer.from(p),this._debug&&this._debug(`Remote ident: ${iu(p)}`),this._compatFlags=hm(E),this._buffer=void 0,this._decipher=new z0(0,J0.bind(this,{firstPacket:!0})),this._parse=fm,this._onHeader(E),this._destruct?(ou(this),t+1-i):e}if(this._server)throw new Error("Greetings from clients not permitted");if(++u>am)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>=om)throw new Error("Header line too long")}a=t}return this._buffer||(this._buffer=au(r,s)),t-i}function fm(n,t,e){return this._decipher.decrypt(n,t,e)}function dm(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===Ie.USERAUTH_SUCCESS&&!this._server&&!this._authenticated&&(this._authenticated=!0,this._kex.negotiated.cs.compress==="zlib@openssh.com"&&(this._packetRW.write=new lu(this)),this._kex.negotiated.sc.compress==="zlib@openssh.com"&&(this._packetRW.read=new cu));let e=Z0[t];if(e===void 0){this._debug&&this._debug(`Inbound: Unsupported message type: ${t}`);return}return e(this,n)}function hm(n){let t=n.versions.software,e=0;for(let r of G0)typeof r[0]=="string"?t===r[0]&&(e|=r[1]):r[0].test(t)&&(e|=r[1]);return e}function pm(n){let t=Object.keys(n),e=Buffer.allocUnsafe(5*t.length+1),r=0;for(let i=0;i<t.length;++i){let s=t[i];if(s==="TTY_OP_END")continue;let o=Ca[s];if(o===void 0)continue;let a=n[s];typeof a=="number"&&isFinite(a)&&(e[r++]=o,e[r++]=a>>>24,e[r++]=a>>>16,e[r++]=a>>>8,e[r++]=a)}return e[r++]=Ca.TTY_OP_END,r<e.length?au(e,0,r):e}function mm(n){let t="ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss";Y0&&(t=`ssh-ed25519,${t}`);let e=Buffer.byteLength(t),r=n._packetRW.write.allocStart,i=n._packetRW.write.alloc(28+e);i[r]=Ie.EXT_INFO,O(i,1,++r),O(i,15,r+=4),i.utf8Write("server-sig-algs",r+=4,15),O(i,e,r+=15),i.utf8Write(t,r+=4,e),n._debug&&n._debug("Outbound: Sending EXT_INFO"),Ce(n,n._packetRW.write.finalize(i))}fu.exports=ka});var Au=lt(vi=>{"use strict";var Bs=require("assert"),{inspect:gm}=require("util");function du(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 hu(n,t){if(Bs(typeof t=="string","`thing` has to be of type string"),Array.isArray(n)){let e=n.length;return Bs(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)}`}vi.ERR_INTERNAL_ASSERTION=class mu extends Error{constructor(t){super(),Error.captureStackTrace(this,mu);let e=`This is caused by either a bug in ssh2 or incorrect usage of ssh2 internals.
13
13
  Please open an issue with this stack trace at https://github.com/mscdex/ssh2/issues
14
14
  `;this.message=t===void 0?e:`${t}
15
- ${e}`}};var mm=2**32,du=(()=>{try{return new Function("return 2n ** 32n")()}catch{}})();ki.ERR_OUT_OF_RANGE=class pu extends RangeError{constructor(t,e,r,s){super(),Error.captureStackTrace(this,pu),Ns(e,'Missing "range" argument');let i=s?t:`The value of "${t}" is out of range.`,o;Number.isInteger(r)&&Math.abs(r)>mm?o=uu(String(r)):typeof r=="bigint"?(o=String(r),(r>du||r<-du)&&(o=uu(o)),o+="n"):o=pm(r),i+=` It must be ${e}. Received ${o}`,this.message=i}};var Bs=class n extends TypeError{constructor(t,e,r){super(),Error.captureStackTrace(this,n),Ns(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} ${fu(e,"type")}`;else{let o=t.includes(".")?"property":"argument";i=`The "${t}" ${o} ${s} ${fu(e,"type")}`}i+=`. Received type ${typeof r}`,this.message=i}};ki.ERR_INVALID_ARG_TYPE=Bs;ki.validateNumber=function(t,e){if(typeof t!="number")throw new Bs(e,"number",t)}});var vi=lt((AE,vu)=>{"use strict";var gm=require("events"),Zn=require("fs"),{constants:sn}=Zn,{Readable:bu,Writable:Ma}=require("stream"),{inherits:Su,types:{isDate:Na}}=require("util"),Am=Buffer[Symbol.species],{bufferCopy:Jn,bufferSlice:qr,makeBufferParser:ym,writeUInt32BE:G}=En(),Hn={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},Em=new Map(Object.values(nt).map(n=>[n,1])),_m={[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},on={VERSION:2,STATUS:101,HANDLE:102,DATA:103,NAME:104,ATTRS:105,EXTENDED:201},ke={READ:1,WRITE:2,APPEND:4,CREAT:8,TRUNC:16,EXCL:32},gu=2*1024,pt=2**32-1,bm=Buffer.from([0,0,0,5,Be.INIT,0,0,0,3]),Sm=Buffer.from([0,0,0,5,on.VERSION,0,0,0,3]),xm=/^SSH-2.0-(?:OpenSSH|dropbear)/,ka=256*1024,Q=ym(),wm={readable:!1,writable:!1,push:n=>{},once:()=>{},on:()=>{},emit:()=>{},end:()=>{}};function xu(){}var Ba=class extends gm{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&&xm.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=ka,this._maxOutPktLen=34e3,this._maxReadLen=(this._isOpenSSH?ka:34e3)-gu,this._maxWriteLen=(this._isOpenSSH?ka:34e3)-gu,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=wm,this.readable=!0}push(t){if(t===null){if(ku(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 at(this,"Invalid packet length");if(this._pktLen>this._maxInPktLen){let a=this._maxInPktLen;return at(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 Am(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?Nm[r]:vm[r];if(!i)return at(this,`Unknown packet type ${r}`);if(this._version===-1){if(this.server){if(r!==Be.INIT)return at(this,`Expected INIT packet, got ${r}`)}else if(r!==on.VERSION)return at(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=xu,this.server||Ze(this,bm)}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 yn(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:Iu(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,u=Buffer.allocUnsafe(13+c+4+4+a);G(u,u.length-4,0),u[4]=Be.OPEN;let f=this._writeReqid=this._writeReqid+1&pt;G(u,f,5),G(u,c,l),u.utf8Write(t,l+=4,c),G(u,i,l+=c),G(u,o,l+=4),a&&(l+=4,a===Pe.length?u.set(Pe,l):Jn(Pe,u,0,a,l),l+=a),this._requests[f]={cb:s};let h=Ze(this,u);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);G(i,i.length-4,0),i[4]=Be.CLOSE;let o=this._writeReqid=this._writeReqid+1&pt;G(i,o,5),G(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");wu(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 u=t.length,f=9,h=Buffer.allocUnsafe(13+u+8+4+s);G(h,h.length-4,0),h[4]=Be.WRITE;let p=this._writeReqid=this._writeReqid+1&pt;G(h,p,5),G(h,u,f),h.set(t,f+=4),f+=u;for(let E=7;E>=0;--E)h[f+E]=i&255,i/=256;G(h,s,f+=8),Jn(e,h,r,r+s,f+=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 y=Ze(this,h);if(this._debug){let E=y?"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");Au(this,Zn,t,e,r,s)}fastPut(t,e,r,s){if(this.server)throw new Error("Client-only method called in server mode");Au(Zn,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,u,f=0,h=e.flag||"r",p=()=>{o===0?(a=Buffer.allocUnsafe(8192),this.read(u,a,0,8192,f,y)):this.read(u,a,l,o-l,f,y)},y=(S,x)=>{let P;if(S){if(P=S.code===nt.EOF,!P)return this.close(u,()=>s&&s(S))}else P=!1;if(P||o===0&&x===0)return E();f+=x,l+=x,o!==0?l===o?E():p():(c.push(qr(a,0,x)),p())};y._wantEOFError=!0;let E=()=>{this.close(u,S=>(o===0?a=Buffer.concat(c,l):l<o&&(a=qr(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);u=x;let P=(q,C)=>{if(q){this.stat(t,($,F)=>{if($)return this.close(u,()=>{s&&s(q)});P(null,F)});return}if(o=C.size||0,o===0)return c=[],p();a=Buffer.allocUnsafe(o),p()};this.fstat(u,P)})}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"),u=/a/.test(o)?null:0;if(u===null){let f=(h,p)=>{if(h){this.stat(t,(y,E)=>{if(y)return this.close(c,()=>{i&&i(h)});f(null,E)});return}Ra(this,c,l,0,l.length,p.size,i)};this.fstat(c,f);return}Ra(this,c,l,0,l.length,u,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);G(i,i.length-4,0),i[4]=Be.REMOVE;let o=this._writeReqid=this._writeReqid+1&pt;G(i,o,5),G(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);G(a,a.length-4,0),a[4]=Be.RENAME;let c=this._writeReqid=this._writeReqid+1&pt;G(a,c,5),G(a,s,o),a.utf8Write(t,o+=4,s),G(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);G(c,c.length-4,0),c[4]=Be.MKDIR;let l=this._writeReqid=this._writeReqid+1&pt;G(c,l,5),G(c,o,a),c.utf8Write(t,a+=4,o),G(c,s,a+=o),i&&(a+=4,i===Pe.length?c.set(Pe,a):Jn(Pe,c,0,i,a),a+=i),this._requests[l]={cb:r};let u=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${u?"Buffered":"Sending"} MKDIR`)}rmdir(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),s=9,i=Buffer.allocUnsafe(13+r);G(i,i.length-4,0),i[4]=Be.RMDIR;let o=this._writeReqid=this._writeReqid+1&pt;G(i,o,5),G(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 u=[],f=0,h=(p,y)=>{if(p)return r(p);this.readdir(y,e,(E,S)=>{let x=E&&E.code===nt.EOF;if(E&&!x)return this.close(y,()=>r(E));if(x)return this.close(y,P=>{if(P)return r(P);r(void 0,u)});for(let P=0;P<S.length;++P,++f)u[f]=S[P];h(void 0,y)})};return this.opendir(t,h)}let i=t.length,o=9,a=Buffer.allocUnsafe(13+i);G(a,a.length-4,0),a[4]=Be.READDIR;let c=this._writeReqid=this._writeReqid+1&pt;G(a,c,5),G(a,i,o),a.set(t,o+=4),this._requests[c]={cb:s?(u,f)=>{if(typeof r=="function"){if(u)return r(u);for(let h=f.length-1;h>=0;--h)(f[h].filename==="."||f[h].filename==="..")&&f.splice(h,1);r(void 0,f)}}: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);G(i,i.length-4,0),i[4]=Be.FSTAT;let o=this._writeReqid=this._writeReqid+1&pt;G(i,o,5),G(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);G(i,i.length-4,0),i[4]=Be.STAT;let o=this._writeReqid=this._writeReqid+1&pt;G(i,o,5),G(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);G(i,i.length-4,0),i[4]=Be.LSTAT;let o=this._writeReqid=this._writeReqid+1&pt;G(i,o,5),G(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);G(i,i.length-4,0),i[4]=Be.OPENDIR;let o=this._writeReqid=this._writeReqid+1&pt;G(i,o,5),G(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);G(c,c.length-4,0),c[4]=Be.SETSTAT;let l=this._writeReqid=this._writeReqid+1&pt;G(c,l,5),G(c,o,a),c.utf8Write(t,a+=4,o),G(c,s,a+=o),i&&(a+=4,i===Pe.length?c.set(Pe,a):Jn(Pe,c,0,i,a),a+=i),this._requests[l]={cb:r};let u=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${u?"Buffered":"Sending"} SETSTAT`)}fsetstat(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let 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);G(c,c.length-4,0),c[4]=Be.FSETSTAT;let l=this._writeReqid=this._writeReqid+1&pt;G(c,l,5),G(c,o,a),c.set(t,a+=4),G(c,s,a+=o),i&&(a+=4,i===Pe.length?c.set(Pe,a):Jn(Pe,c,0,i,a),a+=i),this._requests[l]={cb:r};let u=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${u?"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);G(i,i.length-4,0),i[4]=Be.READLINK;let o=this._writeReqid=this._writeReqid+1&pt;G(i,o,5),G(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);G(a,a.length-4,0),a[4]=Be.SYMLINK;let c=this._writeReqid=this._writeReqid+1&pt;G(a,c,5),this._isOpenSSH?(G(a,i,o),a.utf8Write(t,o+=4,i),G(a,s,o+=i),a.utf8Write(e,o+=4,s)):(G(a,s,o),a.utf8Write(e,o+=4,s),G(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);G(i,i.length-4,0),i[4]=Be.REALPATH;let o=this._writeReqid=this._writeReqid+1&pt;G(i,o,5),G(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);G(c,c.length-4,0),c[4]=Be.EXTENDED;let l=this._writeReqid=this._writeReqid+1&pt;G(c,l,5),G(c,24,a),c.utf8Write("posix-rename@openssh.com",a+=4,24),G(c,i,a+=24),c.utf8Write(t,a+=4,i),G(c,o,a+=i),c.utf8Write(e,a+=4,o),this._requests[l]={cb:r};let u=Ze(this,c);if(this._debug){let f=u?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} 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);G(o,o.length-4,0),o[4]=Be.EXTENDED;let a=this._writeReqid=this._writeReqid+1&pt;G(o,a,5),G(o,19,i),o.utf8Write("statvfs@openssh.com",i+=4,19),G(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);G(o,o.length-4,0),o[4]=Be.EXTENDED;let a=this._writeReqid=this._writeReqid+1&pt;G(o,a,5),G(o,20,i),o.utf8Write("fstatvfs@openssh.com",i+=4,20),G(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);G(c,c.length-4,0),c[4]=Be.EXTENDED;let l=this._writeReqid=this._writeReqid+1&pt;G(c,l,5),G(c,20,a),c.utf8Write("hardlink@openssh.com",a+=4,20),G(c,i,a+=20),c.utf8Write(t,a+=4,i),G(c,o,a+=i),c.utf8Write(e,a+=4,o),this._requests[l]={cb:r};let u=Ze(this,c);if(this._debug){let f=u?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} 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);G(o,o.length-4,0),o[4]=Be.EXTENDED;let a=this._writeReqid=this._writeReqid+1&pt;G(o,a,5),G(o,17,i),o.utf8Write("fsync@openssh.com",i+=4,17),G(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);G(l,l.length-4,0),l[4]=Be.EXTENDED;let u=this._writeReqid=this._writeReqid+1&pt;G(l,u,5),G(l,20,c),l.utf8Write("lsetstat@openssh.com",c+=4,20),G(l,a,c+=20),l.utf8Write(t,c+=4,a),G(l,i,c+=a),o&&(c+=4,o===Pe.length?l.set(Pe,c):Jn(Pe,l,0,o,c),c+=o),this._requests[u]={cb:r};let f=Ze(this,l);if(this._debug){let h=f?"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);G(o,o.length-4,0),o[4]=Be.EXTENDED;let a=this._writeReqid=this._writeReqid+1&pt;G(o,a,5),G(o,23,i),o.utf8Write("expand-path@openssh.com",i+=4,23),G(o,s,i+=20),o.utf8Write(t,i+=4,s),this._requests[a]={cb:(l,u)=>{if(typeof e=="function"){if(l)return e(l);if(!u||!u.length)return e(new Error("Response missing expanded path"));e(void 0,u[0].filename)}}};let c=Ze(this,o);if(this._debug){let 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);G(l,l.length-4,c),c+=4,l[c]=Be.EXTENDED,++c;let u=this._writeReqid=this._writeReqid+1&pt;G(l,u,c),c+=4,G(l,9,c),c+=4,l.utf8Write("copy-data",c,9),c+=9,G(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,G(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[u]={cb:o};let f=Ze(this,l);if(this._debug){let h=f?"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);G(o,o.length-4,s),s+=4,o[s]=Be.EXTENDED,++s;let a=this._writeReqid=this._writeReqid+1&pt;G(o,a,s),s+=4,G(o,14,s),s+=4,o.utf8Write("home-directory",s,14),s+=14,G(o,i,s),s+=4,o.utf8Write(t,s,i),s+=i,this._requests[a]={cb:(l,u)=>{if(typeof e=="function"){if(l)return e(l);if(!u||!u.length)return e(new Error("Response missing home directory"));e(void 0,u[0].filename)}}};let c=Ze(this,o);if(this._debug){let 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);G(o,o.length-4,i),i+=4,o[i]=Be.EXTENDED,++i;let a=this._writeReqid=this._writeReqid+1&pt;G(o,a,i),i+=4,G(o,30,i),i+=4,o.utf8Write("users-groups-by-id@openssh.com",i,30),i+=30,G(o,4*t.length,i),i+=4;for(let l of t)G(o,l,i),i+=4;G(o,4*e.length,i),i+=4;for(let l of e)G(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);G(i,i.length-4,0),i[4]=on.HANDLE,G(i,t,5),G(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(!Em.has(e))throw new Error(`Bad status code: ${e}`);r||(r="");let s=Buffer.byteLength(r),i=9,o=Buffer.allocUnsafe(17+s+4);G(o,o.length-4,0),o[4]=on.STATUS,G(o,t,5),G(o,e,i),G(o,s,i+=4),i+=4,s&&(o.utf8Write(r,i,s),i+=s),G(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);G(c,c.length-4,0),c[4]=on.DATA,G(c,t,5),G(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 u=0;u<r;++u){let f=e[u],h=!f||!f.filename||typeof f.filename!="string"?"":f.filename;s+=4+Buffer.byteLength(h);let p=!f||!f.longname||typeof f.longname!="string"?"":f.longname;if(s+=4+Buffer.byteLength(p),typeof f.attrs=="object"&&f.attrs!==null){if(i=gr(f.attrs),s+=4+i.nb,i.nb){let y;i.nb===Pe.length?y=new Uint8Array(Pe):(y=new Uint8Array(i.nb),Jn(Pe,y,0,i.nb,0)),i.bytes=y}o.push(i)}else s+=4,o.push(null)}let a=9,c=Buffer.allocUnsafe(13+s);G(c,c.length-4,0),c[4]=on.NAME,G(c,t,5),G(c,r,a),a+=4;for(let u=0;u<r;++u){let f=e[u];{let p=!f||!f.filename||typeof f.filename!="string"?"":f.filename,y=Buffer.byteLength(p);G(c,y,a),a+=4,y&&(c.utf8Write(p,a,y),a+=y)}{let p=!f||!f.longname||typeof f.longname!="string"?"":f.longname,y=Buffer.byteLength(p);G(c,y,a),a+=4,y&&(c.utf8Write(p,a,y),a+=y)}let h=o[u];h?(G(c,h.flags,a),a+=4,h.flags&&h.bytes&&(c.set(h.bytes,a),a+=h.nb)):(G(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);G(o,o.length-4,0),o[4]=on.ATTRS,G(o,t,5),G(o,r,i),s&&(i+=4,s===Pe.length?o.set(Pe,i):Jn(Pe,o,0,s,i),i+=s);let a=Ze(this,o);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} ATTRS`)}};function Im(n){try{return Buffer.allocUnsafe(n)}catch(t){return t}}function wu(n,t,e,r,s,i,o,a){let c=n._maxReadLen,l=Math.max(s-c,0);l&&(s=c);let u=t.length,f=9,h=i,p=Buffer.allocUnsafe(13+u+8+4);G(p,p.length-4,0),p[4]=Be.READ;let y=n._writeReqid=n._writeReqid+1&pt;G(p,y,5),G(p,u,f),p.set(t,f+=4),f+=u;for(let x=7;x>=0;--x)p[f+x]=h&255,h/=256;G(p,s,f+=8),typeof o!="function"&&(o=xu);let E=a||{nb:0,position:i,off:r,origOff:r,len:void 0,overflow:void 0,cb:(x,P,q)=>{let C=E.len,$=E.overflow;if(x){if(o._wantEOFError||x.code!==nt.EOF)return o(x)}else{if(q>C)return o(new Error("Received more data than requested"));if(q===C&&$){E.nb+=q,E.position+=q,E.off+=q,wu(n,t,e,E.off,$,E.position,o,E);return}}q=q||0,E.origOff===0&&e.length===E.nb?P=e:P=qr(e,E.origOff,E.origOff+E.nb+q),o(void 0,E.nb+q,P,E.position)},buffer:void 0};E.len=s,E.overflow=l,E.buffer=qr(e,r,r+s),n._requests[y]=E;let S=Ze(n,p);n._debug&&n._debug(`SFTP: Outbound: ${S?"Buffered":"Sending"} READ`)}function Au(n,t,e,r,s,i){let o=64,a=32768,c,l,u;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)&&(u=s.fileSize),typeof s.step=="function"&&(c=s.step),(typeof s.mode=="string"||typeof s.mode=="number")&&(l=La(s.mode)));let f,h=0,p=0,y=!1,E,S,x,P=a*o;function q(C){if(y)return;y=!0;let $=0,F;E||S?(F=()=>{--$===0&&i(C)},E&&(n===Zn||n.outgoing.state==="open")&&++$,S&&(t===Zn||t.outgoing.state==="open")&&++$,E&&(n===Zn||n.outgoing.state==="open")&&n.close(E,F),S&&(t===Zn||t.outgoing.state==="open")&&t.close(S,F)):i(C)}n.open(e,"r",(C,$)=>{if(C)return q(C);E=$,u===void 0?n.fstat(E,F):F(null,{size:u});function F(v,b){if(v){if(n!==Zn){n.stat(e,(w,k)=>{if(w)return q(v);F(null,k)});return}return q(v)}f=b.size,t.open(r,"w",(w,k)=>{if(w)return q(w);if(S=k,f<=0)return q();for(;P>f;){if(o===1){P=f;break}P-=a,--o}if(x=Im(P),x instanceof Error)return q(x);l!==void 0?t.fchmod(S,l,function X(re){if(re){t.chmod(r,l,fe=>X());return}j()}):j();function N(X,re,fe,H,B,L){if(X)return q(X);B=B||0,t.write(S,x,B,re,H,z);function z(ne){if(ne)return q(ne);if(p+=re,c&&c(p,re,f),re<L)return ie(B,H+re,L-re);if(p===f){t.close(S,oe=>{if(S=void 0,oe)return q(oe);n.close(E,Xe=>{if(E=void 0,Xe)return q(Xe);i()})});return}if(h>=f)return;let de=h+a>f?f-h:a;ie(B,h,de),h+=de}}function R(X,re,fe){return(H,B,L)=>{N(H,B,L,re,X,fe)}}function ie(X,re,fe){n.read(E,x,X,fe,re,R(X,re,fe))}function j(){let X=0,re=0;for(;h<f&&X<o;){let fe=h+a>f?f-h:a;ie(re,h,fe),re+=fe,h+=fe,++X}}})}})}function Ra(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,Ra(n,t,e,r,s,i,a))})}var Ps=class{constructor(t){this.mode=t&&t.mode,this.uid=t&&t.uid,this.gid=t&&t.gid,this.size=t&&t.size,this.atime=t&&t.atime,this.mtime=t&&t.mtime,this.extended=t&&t.extended}isDirectory(){return(this.mode&sn.S_IFMT)===sn.S_IFDIR}isFile(){return(this.mode&sn.S_IFMT)===sn.S_IFREG}isBlockDevice(){return(this.mode&sn.S_IFMT)===sn.S_IFBLK}isCharacterDevice(){return(this.mode&sn.S_IFMT)===sn.S_IFCHR}isSymbolicLink(){return(this.mode&sn.S_IFMT)===sn.S_IFLNK}isFIFO(){return(this.mode&sn.S_IFMT)===sn.S_IFIFO}isSocket(){return(this.mode&sn.S_IFMT)===sn.S_IFSOCK}};function gr(n){let t=0,e=0;if(typeof n=="object"&&n!==null){if(typeof n.size=="number"){t|=Hn.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|=Hn.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=La(n.mode);t|=Hn.PERMISSIONS,Pe[e++]=r>>>24,Pe[e++]=r>>>16,Pe[e++]=r>>>8,Pe[e++]=r}if((typeof n.atime=="number"||Na(n.atime))&&(typeof n.mtime=="number"||Na(n.mtime))){let r=Qr(n.atime),s=Qr(n.mtime);t|=Hn.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 Qr(n){if(typeof n=="number"&&n===n)return n;if(Na(n))return parseInt(n.getTime()/1e3,10);throw new Error(`Cannot parse time: ${n}`)}function La(n){if(typeof n=="number"&&n===n)return n;if(typeof n=="string")return La(parseInt(n,8));throw new Error(`Cannot parse mode: ${n}`)}var Pa={r:ke.READ,"r+":ke.READ|ke.WRITE,w:ke.TRUNC|ke.CREAT|ke.WRITE,wx:ke.TRUNC|ke.CREAT|ke.WRITE|ke.EXCL,xw:ke.TRUNC|ke.CREAT|ke.WRITE|ke.EXCL,"w+":ke.TRUNC|ke.CREAT|ke.READ|ke.WRITE,"wx+":ke.TRUNC|ke.CREAT|ke.READ|ke.WRITE|ke.EXCL,"xw+":ke.TRUNC|ke.CREAT|ke.READ|ke.WRITE|ke.EXCL,a:ke.APPEND|ke.CREAT|ke.WRITE,ax:ke.APPEND|ke.CREAT|ke.WRITE|ke.EXCL,xa:ke.APPEND|ke.CREAT|ke.WRITE|ke.EXCL,"a+":ke.APPEND|ke.CREAT|ke.READ|ke.WRITE,"ax+":ke.APPEND|ke.CREAT|ke.READ|ke.WRITE|ke.EXCL,"xa+":ke.APPEND|ke.CREAT|ke.READ|ke.WRITE|ke.EXCL};function Iu(n){let t=Pa[n];return t!==void 0?t:null}var Cm=(()=>{let n=Object.keys(Pa);return t=>{for(let e=0;e<n.length;++e){let r=n[e];if(Pa[r]===t)return r}return null}})();function Wr(n){let t=Q.readUInt32BE();if(t===void 0)return;let e=new Ps;if(t&Hn.SIZE){let r=Q.readUInt64BE(n);if(r===void 0)return;e.size=r}if(t&Hn.UIDGID){let r=Q.readUInt32BE(),s=Q.readUInt32BE();if(s===void 0)return;e.uid=r,e.gid=s}if(t&Hn.PERMISSIONS){let r=Q.readUInt32BE();if(r===void 0)return;e.mode=r}if(t&Hn.ACMODTIME){let r=Q.readUInt32BE(),s=Q.readUInt32BE();if(s===void 0)return;e.atime=r,e.mtime=s}if(t&Hn.EXTENDED){let r=Q.readUInt32BE();if(r===void 0)return;let s={};for(let i=0;i<r;++i){let o=Q.readString(!0),a=Q.readString();if(a===void 0)return;s[o]=a}e.extended=s}return e}function Ze(n,t){let e=Cu(n,t);return e!==void 0?(n._buffer.push(e),!1):!0}function Cu(n,t){let e=n.outgoing;if(e.state!=="open")return;if(e.window===0)return n._waitWindow=!0,n._chunkcb=yu,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=yu),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 yu(){this._chunkcb=void 0;let n=this._buffer,t=0;for(;t<n.length;){let e=n[t],r=Cu(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 at(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(),ku(n),!1}function ku(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 km(n,t){let e=9,r=Buffer.allocUnsafe(31);G(r,r.length-4,0),r[4]=Be.EXTENDED;let s=n._writeReqid=n._writeReqid+1&pt;G(r,s,5),G(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 vm={[on.VERSION]:(n,t)=>{if(n._version!==-1)return at(n,"Duplicate VERSION packet");let e={};Q.init(t,1);let r=Q.readUInt32BE();for(;Q.avail();){let s=Q.readString(!0),i=Q.readString(!0);if(i===void 0){r=void 0;break}e[s]=i}if(Q.clear(),r===void 0)return at(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 km(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")},[on.STATUS]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readUInt32BE(),s=Q.readString(!0);if(Q.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||_m[r]||"Unknown status");o.code=r,i.cb(o)}},[on.HANDLE]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString();if(Q.clear(),r===void 0)return e!==void 0&&delete n._requests[e],at(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)},[on.DATA]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r;if(e!==void 0&&(r=n._requests[e],delete n._requests[e]),r&&typeof r.cb=="function")if(r.buffer){let s=Q.readString(r.buffer);if(Q.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=Q.readString();if(Q.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=Q.skipString();if(Q.clear(),s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${s})`);return}}return at(n,"Malformed DATA packet")},[on.NAME]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let s=Q.readUInt32BE();if(s!==void 0){let i=[];for(let o=0;o<s;++o){let a=Q.readString(!0),c=Q.readString(!0),l=Wr(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})`),Q.clear(),r&&typeof r.cb=="function"&&r.cb(void 0,i);return}}return Q.clear(),at(n,"Malformed NAME packet")},[on.ATTRS]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let s=Wr(n._biOpt);if(Q.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 at(n,"Malformed ATTRS packet")},[on.EXTENDED]:(n,t)=>{Q.init(t,1);let e=Q.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:Q.readUInt64BE(s),f_frsize:Q.readUInt64BE(s),f_blocks:Q.readUInt64BE(s),f_bfree:Q.readUInt64BE(s),f_bavail:Q.readUInt64BE(s),f_files:Q.readUInt64BE(s),f_ffree:Q.readUInt64BE(s),f_favail:Q.readUInt64BE(s),f_sid:Q.readUInt64BE(s),f_flag:Q.readUInt64BE(s),f_namemax:Q.readUInt64BE(s)};if(i.f_namemax===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),Q.clear(),typeof r.cb=="function"&&r.cb(void 0,i);return}case"limits@openssh.com":{let s={maxPktLen:Q.readUInt64BE(),maxReadLen:Q.readUInt64BE(),maxWriteLen:Q.readUInt64BE(),maxOpenHandles:Q.readUInt64BE()};if(s.maxOpenHandles===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),Q.clear(),typeof r.cb=="function"&&r.cb(void 0,s);return}case"users-groups-by-id@openssh.com":{let s=Q.readUInt32BE();if(s===void 0)break;let i=new Array(s);for(let c=0;c<i.length;++c)i[c]=Q.readString(!0);let o=Q.readUInt32BE();if(o===void 0)break;let a=new Array(o);for(let c=0;c<a.length;++c)a[c]=Q.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})`),Q.clear(),typeof r.cb=="function"&&r.cb(void 0,i,a);return}default:n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),Q.clear(),typeof r.cb=="function"&&r.cb();return}else{n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),Q.clear();return}}return Q.clear(),at(n,"Malformed EXTENDED_REPLY packet")}},Nm={[Be.INIT]:(n,t)=>{if(n._version!==-1)return at(n,"Duplicate INIT packet");let e={};Q.init(t,1);let r=Q.readUInt32BE();for(;Q.avail();){let s=Q.readString(!0),i=Q.readString(!0);if(i===void 0){r=void 0;break}e[s]=i}if(Q.clear(),r===void 0)return at(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,Sm),n._version=r,n._extensions=e,n.emit("ready")},[Be.OPEN]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0),s=Q.readUInt32BE(),i=Wr(n._biOpt);if(Q.clear(),i===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString();if(Q.clear(),r===void 0||r.length>256)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(),s=Q.readUInt64BE(n._biOpt),i=Q.readUInt32BE();if(Q.clear(),i===void 0||r.length>256)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(),s=Q.readUInt64BE(n._biOpt),i=Q.readString();if(Q.clear(),i===void 0||r.length>256)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(Q.clear(),r===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString();if(Q.clear(),r===void 0||r.length>256)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0),s=Wr(n._biOpt);if(Q.clear(),s===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(),s=Wr(n._biOpt);if(Q.clear(),s===void 0||r.length>256)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(Q.clear(),r===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString();if(Q.clear(),r===void 0||r.length>256)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(Q.clear(),r===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0),s=Wr(n._biOpt);if(Q.clear(),s===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(Q.clear(),r===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(Q.clear(),r===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(Q.clear(),r===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0),s=Q.readString(!0);if(Q.clear(),s===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(Q.clear(),r===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0),s=Q.readString(!0);if(Q.clear(),s===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(r===void 0)return Q.clear(),at(n,"Malformed EXTENDED packet");let s;Q.avail()&&(s=Q.readRaw()),Q.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:Bm,ERR_OUT_OF_RANGE:Rs,validateNumber:Rm}=mu(),Eu=128,Zt,Ta=[];function Pm(n){Ta.length>0?Zt=Ta.pop():Zt=Buffer.allocUnsafe(n),Zt.used=0}function Oa(n,t){if(!Number.isSafeInteger(n))throw Rm(n,t),Number.isInteger(n)?new Rs(t,">= 0 and <= 2 ** 53 - 1",n):new Rs(t,"an integer",n);if(n<0)throw new Rs(t,">= 0 and <= 2 ** 53 - 1",n)}function va(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,bu.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&&(Oa(this.start,"start"),this.pos=this.start),this.end===void 0)this.end=1/0;else if(this.end!==1/0&&(Oa(this.end,"end"),this.start!==void 0&&this.start>this.end))throw new Rs("start",`<= "end" (here: ${this.end})`,this.start);this.on("end",function(){this.autoClose&&this.destroy()}),Buffer.isBuffer(this.handle)||this.open()}Su(Qn,bu);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<Eu)&&Pm(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=va(t.used+i-e);else{let a=r+e&-8,c=va(r+i);a-c>=Eu&&Ta.push(t.slice(c,a))}i>0&&(this.bytesRead+=i,o=t.slice(r,r+i)),this.pos+=i,this.push(o)}),Zt.used=va(Zt.used+e)};Qn.prototype._destroy=function(n,t){if(this._opening&&!Buffer.isBuffer(this.handle)){this.once("open",_u.bind(null,this,t,n));return}_u(this,t,n),this.handle=null,this._opening=!1};function _u(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 yn(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,Ma.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&&(Oa(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()}Su(yn,Ma);yn.prototype._final=function(n){this.autoClose&&this.destroy(),n()};yn.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)}))};yn.prototype._write=function(n,t,e){if(!Buffer.isBuffer(n)){let r=new Bm("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};yn.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 Ma.prototype.destroy!="function"&&(yn.prototype.destroy=Qn.prototype.destroy);yn.prototype._destroy=Qn.prototype._destroy;yn.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()};yn.prototype.destroySoon=yn.prototype.end;Object.defineProperty(yn.prototype,"pending",{get(){return this.handle===null},configurable:!0});vu.exports={flagsToString:Cm,OPEN_MODE:ke,SFTP:Ba,Stats:Ps,STATUS_CODE:nt,stringToFlags:Iu}});var Qa=lt((yE,Pu)=>{"use strict";var{Duplex:Tm,Readable:Om,Writable:Mm}=require("stream"),{CHANNEL_EXTENDED_DATATYPE:{STDERR:Nu}}=Un(),{bufferSlice:Ts}=En(),Lm=32*1024,Ni=2*1024*1024,Fa=Ni/2,Da=class extends Om{constructor(t,e){super(e),this._channel=t}_read(t){this._channel._waitChanDrain&&(this._channel._waitChanDrain=!1,this._channel.incoming.window<=Fa&&Ha(this._channel))}},Ua=class extends Mm{constructor(t){super({highWaterMark:Ni}),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,u=t.length,f=0;if(o.state==="open"){for(;u-f>0&&l>0;){let h=u-f;h>l&&(h=l),h>a&&(h=a),f===0&&h===u?i.channelExtData(c,t,Nu):i.channelExtData(c,Ts(t,f,f+h),Nu),f+=h,l-=h}if(o.window=l,u-f>0){l===0&&(s._waitWindow=!0),f>0?s._chunkErr=Ts(t,f,u):s._chunkErr=t,s._chunkcbErr=r;return}r()}}},$a=class extends Tm{constructor(t,e,r){let s={highWaterMark:Ni,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 Ua(this):this.stderr=new Da(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",Bu).on("prefinish",Bu),this.on("end",Ru).on("close",Ru)}_read(t){this._waitChanDrain&&(this._waitChanDrain=!1,this.incoming.window<=Fa&&Ha(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,u=0;if(i.state==="open"){for(;l-u>0&&c>0;){let f=l-u;f>c&&(f=c),f>o&&(f=o),u===0&&f===l?s.channelData(a,t):s.channelData(a,Ts(t,u,u+f)),u+=f,c-=f}if(i.window=c,l-u>0){c===0&&(this._waitWindow=!0),u>0?this._chunk=Ts(t,u,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 Bu(){this.eof(),(this.server||!this.allowHalfOpen)&&this.close(),this.writable=!1}function Ru(){this.readable=!1}function Ha(n){if(n.outgoing.state==="closed")return;let t=Ni-n.incoming.window;t<=0||(n.incoming.window+=t,n._client._protocol.channelWindowAdjust(n.outgoing.id,t))}Pu.exports={Channel:$a,MAX_WINDOW:Ni,PACKET_SIZE:Lm,windowAdjust:Ha,WINDOW_THRESHOLD:Fa}});var Ka=lt((EE,Mu)=>{"use strict";var{SFTP:Dm}=vi(),Bi=2**32-1;function Tu(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 Ou(n,t,e,r,s){if(typeof e=="function"){Tu(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!==Dm&&(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 u=e._exit;c=()=>{u.code===null?e.emit("close",u.code,u.signal,u.dump,u.desc):e.emit("close",u.code)}}}!e.readable||e.destroyed||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 qa=class{constructor(t){this._client=t,this._channels={},this._cur=-1,this._count=0}add(t){let e;if(this._cur<Bi)e=++this._cur;else if(this._count===0)this._cur=0,e=0;else{let r=this._channels;for(let s=0;s<Bi;++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>=Bi||!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>=Bi||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);return this._channels[t]}remove(t){if(typeof t!="number"||t<0||t>=Bi||!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];Ou(s,o,a._channel||a,t,!0)}}},Wa=(()=>{let n=Object.prototype.toString;return t=>n.call(t)==="[object RegExp]"})();function Um(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(Wa(l))for(let u=0;u<e.length;++u){let f=e[u];if(l.test(f)){if(s.indexOf(f)!==-1)continue;s===t&&(s=s.slice()),s.push(f)}}}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(Wa(l))for(let u=e.length;u>=0;--u){let f=e[u];if(l.test(f)){if(s.indexOf(f)!==-1)continue;s===t&&(s=s.slice()),s.unshift(f)}}}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 u=s.indexOf(l);if(u===-1)continue;s===t&&(s=s.slice()),s.splice(u,1)}else if(Wa(l))for(let u=0;u<s.length;++u)l.test(s[u])&&(s===t&&(s=s.slice()),s.splice(u,1),--u)}break}}return s}return t}Mu.exports={ChannelManager:qa,generateAlgorithmList:Um,onChannelOpenFailure:Tu,onCHANNEL_CLOSE:Ou,isWritable:n=>n&&n.writable&&n._readableState&&n._readableState.ended===!1}});var Ja=lt((_E,tf)=>{"use strict";var{createHash:$m,getHashes:Fm,randomFillSync:Hm}=require("crypto"),{Socket:Qm}=require("net"),{lookup:Wm}=require("dns"),qm=require("events"),Km=Fm(),{COMPAT:Ju,CHANNEL_EXTENDED_DATATYPE:{STDERR:Vm},CHANNEL_OPEN_FAILURE:Ri,DEFAULT_CIPHER:Lu,DEFAULT_COMPRESSION:Du,DEFAULT_KEX:Uu,DEFAULT_MAC:$u,DEFAULT_SERVER_HOST_KEY:Fu,DISCONNECT_REASON:Hu,DISCONNECT_REASON_BY_VALUE:zm,SUPPORTED_CIPHER:Gm,SUPPORTED_COMPRESSION:Ym,SUPPORTED_KEX:jm,SUPPORTED_MAC:Xm,SUPPORTED_SERVER_HOST_KEY:Jm}=Un(),{init:Zm}=Gn(),eg=Ca(),{parseKey:Ls}=Xn(),{SFTP:tg}=vi(),{bufferCopy:Qu,makeBufferParser:Zu,makeError:ng,readUInt32BE:rg,sigSSHToASN1:ig,writeUInt32BE:Va}=En(),{AgentContext:Wu,createAgent:qu,isAgent:Ku}=fa(),{Channel:ef,MAX_WINDOW:Ds,PACKET_SIZE:Us,windowAdjust:Vu,WINDOW_THRESHOLD:zu}=Qa(),{ChannelManager:sg,generateAlgorithmList:Pi,isWritable:Dt,onChannelOpenFailure:og,onCHANNEL_CLOSE:ag}=Ka(),Os=Zu(),Ms=Zu(),Ti=/^OpenSSH_(?:(?![0-4])\d)|(?:\d{2,})/,ja=n=>{},Xa=class extends qm{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&&Dt(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=Pi(t.algorithms.kex,Uu,jm),e.kex!==Uu&&(r=!1),e.serverHostKey=Pi(t.algorithms.serverHostKey,Fu,Jm),e.serverHostKey!==Fu&&(r=!1),e.cs.cipher=Pi(t.algorithms.cipher,Lu,Gm),e.cs.cipher!==Lu&&(r=!1),e.cs.mac=Pi(t.algorithms.hmac,$u,Xm),e.cs.mac!==$u&&(r=!1),e.cs.compress=Pi(t.algorithms.compress,Du,Ym),e.cs.compress!==Du&&(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=qu(t.agent):Ku(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 sg(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=Ls(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 H=t.hostVerifier,B;Km.indexOf(t.hostHash)!==-1&&(B=t.hostHash),c=(L,z)=>{B&&(L=$m(B).update(L).digest("hex"));let ne=H(L,z);ne!==void 0&&z(ne)}}let l=this._sock=t.sock||new Qm,u=!1,f=!1;this._protocol&&this._protocol.cleanup();let h=i?(H,B,L)=>{i(`Debug output from server: ${JSON.stringify(L)}`)}:void 0,p,y=this._protocol=new eg({ident:this.config.ident,offer:r?void 0:e,onWrite:H=>{Dt(l)&&l.write(H)},onError:H=>{H.level==="handshake"&&clearTimeout(this._readyTimeout),y._destruct||l.removeAllListeners("data"),this.emit("error",H);try{l.end()}catch{}},onHeader:H=>{f=!0,this._remoteVer=H.versions.software,H.greeting&&this.emit("greeting",H.greeting)},onHandshakeComplete:H=>{this.emit("handshake",H),u||(u=!0,y.service("ssh-userauth"))},debug:i,hostVerifier:c,messageHandlers:{DEBUG:h,DISCONNECT:(H,B,L)=>{if(B!==Hu.BY_APPLICATION){L||(L=zm[B],L===void 0&&(L=`Unexpected disconnection reason: ${B}`));let z=new Error(L);z.code=B,this.emit("error",z)}l.end()},SERVICE_ACCEPT:(H,B)=>{B==="ssh-userauth"&&X()},EXT_INFO:(H,B)=>{if(p===void 0){for(let L of B)if(L.name==="server-sig-algs"){p=L.algs;return}p=null}},USERAUTH_BANNER:(H,B)=>{this.emit("banner",B)},USERAUTH_SUCCESS:H=>{C(),clearTimeout(this._readyTimeout),this.emit("ready")},USERAUTH_FAILURE:(H,B,L)=>{if(b.keyAlgos){let z=b.keyAlgos[0][0];if(i&&i(`Client: ${b.type} (${z}) auth failed`),b.keyAlgos.shift(),b.keyAlgos.length){let[ne,de]=b.keyAlgos[0];switch(b.type){case"agent":y.authPK(b.username,b.agentCtx.currentKey(),ne);return;case"publickey":y.authPK(b.username,b.key,ne);return;case"hostbased":y.authHostbased(b.username,b.key,b.localHostname,b.localUsername,ne,(oe,Xe)=>{let dt=b.key.sign(oe,de);if(dt instanceof Error)return dt.message=`Error while signing with key: ${dt.message}`,dt.level="client-authentication",this.emit("error",dt),X();Xe(dt)});return}}else b.keyAlgos=void 0}if(b.type==="agent"){let z=b.agentCtx.pos();return i&&i(`Client: Agent key #${z+1} failed`),re()}i&&i(`Client: ${b.type} auth failed`),w=L,k=B,X()},USERAUTH_PASSWD_CHANGEREQ:(H,B)=>{b.type==="password"&&this.emit("change password",B,L=>{y.authPassword(this.config.username,this.config.password,L)})},USERAUTH_PK_OK:H=>{let B,L;if(b.keyAlgos&&([B,L]=b.keyAlgos[0]),b.type==="agent"){let z=b.agentCtx.currentKey();y.authPK(b.username,z,B,(ne,de)=>{let oe={hash:L};b.agentCtx.sign(z,ne,oe,(Xe,dt)=>{if(Xe)Xe.level="agent",this.emit("error",Xe);else return de(dt);re()})})}else b.type==="publickey"&&y.authPK(b.username,b.key,B,(z,ne)=>{let de=b.key.sign(z,L);if(de instanceof Error)return de.message=`Error signing data with key: ${de.message}`,de.level="client-authentication",this.emit("error",de),X();ne(de)})},USERAUTH_INFO_REQUEST:(H,B,L,z)=>{if(b.type==="keyboard-interactive"){if((Array.isArray(z)?z.length:0)===0){i&&i("Client: Sending automatic USERAUTH_INFO_RESPONSE"),y.authInfoRes();return}b.prompt(B,L,"",z,de=>{y.authInfoRes(de)})}},REQUEST_SUCCESS:(H,B)=>{o.length&&o.shift()(!1,B)},REQUEST_FAILURE:H=>{o.length&&o.shift()(!0)},GLOBAL_REQUEST:(H,B,L,z)=>{B==="hostkeys-00@openssh.com"?(dg(this,z,(ne,de)=>{ne||this.emit("hostkeys",de)}),L&&y.requestSuccess()):L&&y.requestFailure()},CHANNEL_OPEN:(H,B)=>{ug(this,B)},CHANNEL_OPEN_CONFIRMATION:(H,B)=>{let L=this._chanMgr.get(B.recipient);if(typeof L!="function")return;let z=L.type==="sftp",de={type:z?"session":L.type,incoming:{id:B.recipient,window:Ds,packetSize:Us,state:"open"},outgoing:{id:B.sender,window:B.window,packetSize:B.packetSize,state:"open"}},oe=z?new tg(this,de,{debug:i}):new ef(this,de);this._chanMgr.update(B.recipient,oe),L(void 0,oe)},CHANNEL_OPEN_FAILURE:(H,B,L,z)=>{let ne=this._chanMgr.get(B);if(typeof ne!="function")return;og(this,B,{reason:L,description:z},ne)},CHANNEL_DATA:(H,B,L)=>{let z=this._chanMgr.get(B);if(!(typeof z!="object"||z===null)&&z.incoming.window!==0){if(z.incoming.window-=L.length,z.push(L)===!1){z._waitChanDrain=!0;return}z.incoming.window<=zu&&Vu(z)}},CHANNEL_EXTENDED_DATA:(H,B,L,z)=>{if(z!==Vm)return;let ne=this._chanMgr.get(B);if(!(typeof ne!="object"||ne===null)&&ne.incoming.window!==0){if(ne.incoming.window-=L.length,!ne.stderr.push(L)){ne._waitChanDrain=!0;return}ne.incoming.window<=zu&&Vu(ne)}},CHANNEL_WINDOW_ADJUST:(H,B,L)=>{let z=this._chanMgr.get(B);typeof z!="object"||z===null||(z.outgoing.window+=L,z._waitWindow&&(z._waitWindow=!1,z._chunk?z._write(z._chunk,null,z._chunkcb):z._chunkcb?z._chunkcb():z._chunkErr?z.stderr._write(z._chunkErr,null,z._chunkcbErr):z._chunkcbErr&&z._chunkcbErr()))},CHANNEL_SUCCESS:(H,B)=>{let L=this._chanMgr.get(B);typeof L!="object"||L===null||(this._resetKA(),L._callbacks.length&&L._callbacks.shift()(!1))},CHANNEL_FAILURE:(H,B)=>{let L=this._chanMgr.get(B);typeof L!="object"||L===null||(this._resetKA(),L._callbacks.length&&L._callbacks.shift()(!0))},CHANNEL_REQUEST:(H,B,L,z,ne)=>{let de=this._chanMgr.get(B);if(typeof de!="object"||de===null)return;let oe=de._exit;if(oe.code===void 0){switch(L){case"exit-status":de.emit("exit",oe.code=ne);return;case"exit-signal":de.emit("exit",oe.code=null,oe.signal=`SIG${ne.signal}`,oe.dump=ne.coreDumped,oe.desc=ne.errorMessage);return}z&&H.channelFailure(de.outgoing.id)}},CHANNEL_EOF:(H,B)=>{let L=this._chanMgr.get(B);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:(H,B)=>{ag(this,B,this._chanMgr.get(B))}}});l.pause();let E=this.config.keepaliveInterval,S=this.config.keepaliveCountMax,x=0,P,q=()=>{if(++x>S){if(clearInterval(P),l.readable){let H=new Error("Keepalive timeout");H.level="client-timeout",this.emit("error",H),l.destroy()}return}Dt(l)?(o.push(C),y.ping()):clearInterval(P)};function C(){E>0&&(x=0,clearInterval(P),Dt(l)&&(P=setInterval(q,E)))}this._resetKA=C;let $=(()=>{let H=!1;return()=>{if(!H&&(H=!0,v&&!f)){let B=ng("Connection lost before handshake","protocol",!0);this.emit("error",B)}}})(),F=(()=>{let H=!1;return()=>{H||(H=!0,v=!0,i&&i("Socket connected"),this.emit("connect"),Zm.then(()=>{y.start(),l.on("data",B=>{try{y.parse(B,0,B.length)}catch(L){this.emit("error",L);try{Dt(l)&&l.end()}catch{}}}),l.stderr&&typeof l.stderr.resume=="function"&&l.stderr.resume(),l.resume()}).catch(B=>{this.emit("error",B);try{Dt(l)&&l.end()}catch{}}))}})(),v=!1;l.on("connect",F).on("timeout",()=>{this.emit("timeout")}).on("error",H=>{i&&i(`Socket error: ${H.message}`),clearTimeout(this._readyTimeout),H.level="client-socket",this.emit("error",H)}).on("end",()=>{i&&i("Socket ended"),$(),y.cleanup(),clearTimeout(this._readyTimeout),clearInterval(P),this.emit("end")}).on("close",()=>{i&&i("Socket closed"),$(),y.cleanup(),clearTimeout(this._readyTimeout),clearInterval(P),this.emit("close");let H=o;o=this._callbacks=[];let B=new Error("No response from server");for(let L=0;L<H.length;++L)H[L](B);this._chanMgr.cleanup(B)});let b,w=null,k=null,N=["none"];this.config.password!==void 0&&N.push("password"),a!==void 0&&N.push("publickey"),this._agent!==void 0&&N.push("agent"),this.config.tryKeyboard&&N.push("keyboard-interactive"),a!==void 0&&this.config.localHostname!==void 0&&this.config.localUsername!==void 0&&N.push("hostbased"),Array.isArray(s)?s=Xu(s):typeof s!="function"&&(s=Xu(N));let R=!1,ie=H=>{if(!R){if(R=!0,H===!1){let B=new Error("All configured authentication methods failed");B.level="client-authentication",this.emit("error",B),this.end();return}if(typeof H=="string"){let B=H;if(N.indexOf(B)===-1)return j(`Authentication method not allowed: ${B}`);let L=this.config.username;switch(B){case"password":H={type:B,username:L,password:this.config.password};break;case"publickey":H={type:B,username:L,key:a};break;case"hostbased":H={type:B,username:L,key:a,localHostname:this.config.localHostname,localUsername:this.config.localUsername};break;case"agent":H={type:B,username:L,agentCtx:new Wu(this._agent)};break;case"keyboard-interactive":H={type:B,username:L,prompt:(...z)=>this.emit("keyboard-interactive",...z)};break;case"none":H={type:B,username:L};break;default:return j(`Skipping unsupported authentication method: ${H}`)}}else{if(typeof H!="object"||H===null)return j(`Skipping invalid authentication attempt: ${H}`);{let B=H.username;if(typeof B!="string")return j(`Skipping invalid authentication attempt: ${H}`);let L=H.type;switch(L){case"password":{let{password:z}=H;if(typeof z!="string"&&!Buffer.isBuffer(z))return j("Skipping invalid password auth attempt");H={type:L,username:B,password:z};break}case"publickey":{let z=Ls(H.key,H.passphrase);if(z instanceof Error)return j("Skipping invalid key auth attempt");if(!z.isPrivateKey())return j("Skipping non-private key");H={type:L,username:B,key:z};break}case"hostbased":{let{localHostname:z,localUsername:ne}=H,de=Ls(H.key,H.passphrase);if(de instanceof Error||typeof z!="string"||typeof ne!="string")return j("Skipping invalid hostbased auth attempt");if(!de.isPrivateKey())return j("Skipping non-private key");H={type:L,username:B,key:de,localHostname:z,localUsername:ne};break}case"agent":{let z=H.agent;if(typeof z=="string"&&z.length)z=qu(z);else if(!Ku(z))return j(`Skipping invalid agent: ${H.agent}`);H={type:L,username:B,agentCtx:new Wu(z)};break}case"keyboard-interactive":{let{prompt:z}=H;if(typeof z!="function")return j("Skipping invalid keyboard-interactive auth attempt");H={type:L,username:B,prompt:z};break}case"none":H={type:L,username:B};break;default:return j(`Skipping unsupported authentication method: ${H}`)}}}b=H;try{let B=b.username;switch(b.type){case"password":y.authPassword(B,b.password);break;case"publickey":{let L;if(b.keyAlgos=Ya(this,b.key,p),b.keyAlgos)if(b.keyAlgos.length)L=b.keyAlgos[0][0];else return j("Skipping key authentication (no mutual hash algorithm)");y.authPK(B,b.key,L);break}case"hostbased":{let L,z;if(b.keyAlgos=Ya(this,b.key,p),b.keyAlgos)if(b.keyAlgos.length)[L,z]=b.keyAlgos[0];else return j("Skipping hostbased authentication (no mutual hash algorithm)");y.authHostbased(B,b.key,b.localHostname,b.localUsername,L,(ne,de)=>{let oe=b.key.sign(ne,z);if(oe instanceof Error)return oe.message=`Error while signing with key: ${oe.message}`,oe.level="client-authentication",this.emit("error",oe),X();de(oe)});break}case"agent":b.agentCtx.init(L=>{if(L)return L.level="agent",this.emit("error",L),X();re()});break;case"keyboard-interactive":y.authKeyboard(B);break;case"none":y.authNone(B);break}}finally{R=!1}}};function j(H){i&&i(H),process.nextTick(X)}function X(){R=!1;let H=s(k,w,ie);R||H===void 0||ie(H)}let re=()=>{if(b.type==="agent"){let H=b.agentCtx.nextKey();if(H===!1)i&&i("Agent: No more keys left to try"),i&&i("Client: agent auth failed"),X();else{let B=b.agentCtx.pos(),L;if(b.keyAlgos=Ya(this,H,p),b.keyAlgos)if(b.keyAlgos.length)L=b.keyAlgos[0][0];else{i&&i(`Agent: Skipping key #${B+1} (no mutual hash algorithm)`),re();return}i&&i(`Agent: Trying key #${B+1}`),y.authPK(b.username,H,L)}}},fe=()=>{this.config.readyTimeout>0&&(this._readyTimeout=setTimeout(()=>{let H=new Error("Timed out while waiting for handshake");H.level="client-timeout",this.emit("error",H),l.destroy()},this.config.readyTimeout))};if(t.sock)fe(),typeof l.connecting=="boolean"&&l.connecting||F();else{let H=this.config.host,B=this.config.forceIPv4,L=this.config.forceIPv6;i&&i(`Client: Trying ${H} on port ${this.config.port} ...`);let z=()=>{fe(),l.connect({host:H,port:this.config.port,localAddress:this.config.localAddress,localPort:this.config.localPort}),l.setMaxListeners(0),l.setTimeout(typeof t.timeout=="number"?t.timeout:0)};!B&&!L||B&&L?z():Wm(H,B?4:6,(ne,de,oe)=>{if(ne){let Xe=B?"IPv4":"IPv6",dt=new Error(`Error while looking up ${Xe} address for '${H}': ${ne}`);clearTimeout(this._readyTimeout),dt.level="client-dns",this.emit("error",dt),this.emit("close");return}H=de,z()})}return this}end(){return this._sock&&Dt(this._sock)&&(this._protocol.disconnect(Hu.BY_APPLICATION),this._sock.end()),this}destroy(){return this._sock&&Dt(this._sock)&&this._sock.destroy(),this}exec(t,e,r){if(!this._sock||!Dt(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(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(()=>ju(o,c)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&za(o,e.env),(typeof e.pty=="object"&&e.pty!==null||e.pty===!0)&&a.push(()=>Yu(o,e.pty,c)),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&a.push(()=>Gu(o,e.x11,c))),a.push(()=>lg(o,t,e,r)),a.shift()()}),this}shell(t,e,r){if(!this._sock||!Dt(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(()=>ju(i,a)),t!==!1&&o.push(()=>Yu(i,t,a)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&za(i,e.env),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&o.push(()=>Gu(i,e.x11,a))),o.push(()=>cg(i,r)),o.shift()()}),this}subsys(t,e){if(!this._sock||!Dt(this._sock))throw new Error("Not connected");return Kr(this,"session",(r,s)=>{if(r){e(r);return}Ga(s,t,(i,o)=>{if(i){e(i);return}e(void 0,o)})}),this}forwardIn(t,e,r){if(!this._sock||!Dt(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=rg(o,0),this._protocol._compatFlags&Ju.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||!Dt(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||!Dt(this._sock))throw new Error("Not connected");let o={srcIP:t,srcPort:e,dstIP:r,dstPort:s};return typeof i!="function"&&(i=ja),Kr(this,"direct-tcpip",o,i),this}openssh_noMoreSessions(t){if(!this._sock||!Dt(this._sock))throw new Error("Not connected");let e=typeof t=="function";return!this.config.strictVendor||this.config.strictVendor&&Ti.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||!Dt(this._sock))throw new Error("Not connected");let r=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&Ti.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||!Dt(this._sock))throw new Error("Not connected");let r=typeof e=="function";return!this.config.strictVendor||this.config.strictVendor&&Ti.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||!Dt(this._sock))throw new Error("Not connected");return typeof e!="function"&&(e=ja),!this.config.strictVendor||this.config.strictVendor&&Ti.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||!Dt(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",l),s.removeListener("error",u),s.removeListener("exit",f),s.removeListener("close",f)}function l(){c(),e(void 0,s)}function u(h){c(),e(h)}function f(h,p){c();let y;typeof h=="number"?y=`Received exit code ${h} while establishing SFTP session`:p!==void 0?y=`Received signal ${p} while establishing SFTP session`:y="Received unexpected SFTP session termination";let E=new Error(y);E.code=h,E.signal=p,e(E)}s.on("ready",l).on("error",u).on("exit",f).on("close",f),s._init()};typeof t=="object"&&t!==null?za(s,t,o=>{if(o){e(o);return}Ga(s,"sftp",i)}):Ga(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=Ds,i=Us;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 Gu(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=fg());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 Yu(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(u=>{if(u){e(u!==!0?u:new Error("Unable to request a pseudo-terminal"));return}e()}),n._client._protocol.pty(n.outgoing.id,r,s,o,i,a,c,l)}function ju(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 cg(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 lg(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 za(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 Ga(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 ug(n,t){let e=-1,r,s=()=>{let c={type:t.type,incoming:{id:e,window:Ds,packetSize:Us,state:"open"},outgoing:{id:t.sender,window:t.window,packetSize:t.packetSize,state:"open"}},l=new ef(n,c);return n._chanMgr.update(e,l),n._protocol.channelOpenConfirm(t.sender,e,Ds,Us),l},i=()=>{r===void 0&&(e===-1?r=Ri.RESOURCE_SHORTAGE:r=Ri.CONNECT_FAILED),e!==-1&&n._chanMgr.remove(e),n._protocol.channelOpenFail(t.sender,r,"")},o=()=>(e=n._chanMgr.add(),e===-1&&(r=Ri.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 u=s();u.pipe(l).pipe(u)});return}break;case"x11":if(n._acceptX11!==0&&o()){n.emit("x11",a,s,i);return}break;default:r=Ri.UNKNOWN_CHANNEL_TYPE,n.config.debug&&n.config.debug(`Client: Automatic rejection of unsupported incoming channel open type: ${t.type}`)}r===void 0&&(r=Ri.ADMINISTRATIVELY_PROHIBITED,n.config.debug&&n.config.debug("Client: Automatic rejection of unexpected incoming channel open for: "+t.type)),i()}var fg=(()=>{let n=Buffer.allocUnsafe(16);return()=>(Hm(n,0,16),n.hexSlice(0,16))})();function Xu(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 dg(n,t,e){if(!n._sock||!Dt(n._sock))return;if(typeof e!="function"&&(e=ja),!Array.isArray(t))throw new TypeError("Invalid keys argument type");let r=[];for(let s of t){let i=Ls(s);if(i instanceof Error)throw i;r.push(i)}if(!n.config.strictVendor||n.config.strictVendor&&Ti.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(Os.init(i,0);Os.avail()&&a!==r.length;){let c=r[a++],l=c.getPublicSSH(),u=Os.readString();Ms.init(u,0);let f=Ms.readString(!0),h=Ms.readString(),p;if(f!==c.type)if(c.type==="ssh-rsa")switch(f){case"rsa-sha2-256":p="sha256";break;case"rsa-sha2-512":p="sha512";break;default:continue}else continue;let y=n._protocol._kex.sessionID,E=Buffer.allocUnsafe(37+y.length+4+l.length),S=0;Va(E,29,S),E.utf8Write("hostkeys-prove-00@openssh.com",S+=4,29),Va(E,y.length,S+=29),Qu(y,E,0,y.length,S+=4),Va(E,l.length,S+=y.length),Qu(l,E,0,l.length,S+=4),(h=ig(h,f))&&c.verify(E,h,p)===!0&&o.push(c)}Ms.clear(),Os.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 Ya(n,t,e){switch(t.type){case"ssh-rsa":if(n._protocol._compatFlags&Ju.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"]]}}tf.exports=Xa});var rf=lt(nf=>{"use strict";var{Agent:ec}=require("http"),{Agent:hg}=require("https"),{connect:pg}=require("tls"),Za;for(let n of[ec,hg]){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;Za===void 0&&(Za=Ja());let l=new Za,u=!1;l.on("ready",()=>{l.forwardOut(i,o,a,c,(f,h)=>{if(u=!0,f)return l.end(),s(f);h.once("close",()=>l.end()),s(null,mg(h,n,r))})}).on("error",s).on("close",()=>{u||s(new Error("Unexpected connection close"))}).connect(this._connectCfg)}}nf[n===ec?"SSHTTPAgent":"SSHTTPSAgent"]=t}function Oi(){}function mg(n,t,e){if(t===ec)return n.setKeepAlive=Oi,n.setNoDelay=Oi,n.setTimeout=Oi,n.ref=Oi,n.unref=Oi,n.destroySoon=n.destroy,n;e.socket=n;let r=pg(e),s=(()=>{let i=!1;return()=>{i||(i=!0,n.isPaused()&&n.resume())}})();return r.on("end",s).on("close",s),r}});var of=lt((SE,ic)=>{"use strict";var{Server:gg}=require("net"),Li=require("events"),{listenerCount:Xt}=Li,{CHANNEL_OPEN_FAILURE:Vr,DEFAULT_CIPHER:Ag,DEFAULT_COMPRESSION:yg,DEFAULT_KEX:Eg,DEFAULT_MAC:_g,DEFAULT_SERVER_HOST_KEY:bg,DISCONNECT_REASON:zr,DISCONNECT_REASON_BY_VALUE:Sg,SUPPORTED_CIPHER:xg,SUPPORTED_COMPRESSION:wg,SUPPORTED_KEX:Ig,SUPPORTED_MAC:Cg,SUPPORTED_SERVER_HOST_KEY:kg}=Un(),{init:vg}=Gn(),{KexInit:Ng}=bs(),{parseKey:sf}=Xn(),Bg=Ca(),{SFTP:Rg}=vi(),{writeUInt32BE:Pg}=En(),{Channel:Gr,MAX_WINDOW:er,PACKET_SIZE:tr,windowAdjust:Tg,WINDOW_THRESHOLD:Og}=Qa(),{ChannelManager:Mg,generateAlgorithmList:Mi,isWritable:$s,onChannelOpenFailure:Lg,onCHANNEL_CLOSE:Dg}=Ka(),Ug=10,nr=class extends Li{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)}},Fs=class extends nr{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)}},nc=class extends nr{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?nr.prototype.accept.call(this):(this._initialResponse=!0,this._protocol.authPKOK(this.key.algo,this.key.data))}},rc=class extends nr{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}},Hs=class extends nr{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 Li{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:er,packetSize:tr,state:"open"},outgoing:{id:e.sender,window:e.window,packetSize:e.packetSize,state:"open"}}}},dn=class extends Li{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=Mi(o.serverHostKey,bg,kg);for(let h=0;h<i.length;++h){let p;if(Buffer.isBuffer(i[h])||typeof i[h]=="string"?p=sf(i[h]):p=sf(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 y=a.indexOf("ssh-rsa"),E=a.indexOf("rsa-sha2-256"),S=a.indexOf("rsa-sha2-512");y===-1&&(y=1/0),[y,E,S].sort($g).forEach(x=>{if(x===-1)return;let P;switch(x){case y:P="ssh-rsa";break;case E:P="rsa-sha2-256";break;case S:P="rsa-sha2-512";break;default:return}r[P]=p,s.push(P)})}else r[p.type]=p,s.push(p.type)}let c={kex:Mi(o.kex,Eg,Ig).concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:s,cs:{cipher:Mi(o.cipher,Ag,xg),mac:Mi(o.hmac,_g,Cg),compress:Mi(o.compress,yg,wg),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,u=t.ident?Buffer.from(t.ident):void 0,f=new Ng(c);this._srv=new gg(h=>{if(this._connections>=this.maxConnections){h.destroy();return}++this._connections,h.once("close",()=>{--this._connections});let p;if(l){let y=`[${process.hrtime().join(".")}] `;p=E=>{l(`${y}${E}`)}}new Qs(h,r,u,f,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}};dn.KEEPALIVE_CLIENT_INTERVAL=15e3;dn.KEEPALIVE_CLIENT_COUNT_MAX=3;var Qs=class extends Li{constructor(t,e,r,s,i,o,a){super();let c=0,l=!1,u=[],f,h,p,y=[];this._sock=t,this._chanMgr=new Mg(this),this._debug=i,this.noMoreSessions=!1,this.authenticated=!1;function E(v){}this.on("error",E);let S=i?(v,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 dn.KEEPALIVE_CLIENT_INTERVAL=="number"&&isFinite(dn.KEEPALIVE_CLIENT_INTERVAL)&&dn.KEEPALIVE_CLIENT_INTERVAL>0?dn.KEEPALIVE_CLIENT_INTERVAL:-1,P=typeof a.keepaliveCountMax=="number"&&isFinite(a.keepaliveCountMax)&&a.keepaliveCountMax>=0?a.keepaliveCountMax:typeof dn.KEEPALIVE_CLIENT_COUNT_MAX=="number"&&isFinite(dn.KEEPALIVE_CLIENT_COUNT_MAX)&&dn.KEEPALIVE_CLIENT_COUNT_MAX>=0?dn.KEEPALIVE_CLIENT_COUNT_MAX:-1,q=0;x!==-1&&P!==-1&&(this.once("ready",()=>{let v=()=>{clearInterval(h)};this.on("close",v).on("end",v),h=setInterval(()=>{if(++q>P){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(),q=0});let C=this._protocol=new Bg({server:!0,hostKeys:e,ident:r,offer:s,onPacket:p,greeting:a.greeting,banner:a.banner,onWrite:v=>{$s(t)&&t.write(v)},onError:v=>{C._destruct||t.removeAllListeners("data"),this.emit("error",v);try{t.end()}catch{}},onHeader:v=>{this.removeListener("error",E);let b={ip:t.remoteAddress,family:t.remoteFamily,port:t.remotePort,header:v};if(!o.emit("connection",this,b)){C.disconnect(zr.BY_APPLICATION),t.end();return}v.greeting&&this.emit("greeting",v.greeting)},onHandshakeComplete:v=>{++c>1&&this.emit("rekey"),this.emit("handshake",v)},debug:i,messageHandlers:{DEBUG:S,DISCONNECT:(v,b,w)=>{if(b!==zr.BY_APPLICATION){w||(w=Sg[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:(v,b)=>{if(b.type==="session"&&this.noMoreSessions||!this.authenticated){let re=Vr.ADMINISTRATIVELY_PROHIBITED;return C.channelOpenFail(b.sender,re)}let w=-1,k,N=!1,R,ie=()=>{N||(N=!0,k===void 0&&(w===-1?k=Vr.RESOURCE_SHORTAGE:k=Vr.CONNECT_FAILED),w!==-1&&this._chanMgr.remove(w),C.channelOpenFail(b.sender,k,""))},j=()=>(w=this._chanMgr.add(),w===-1&&(k=Vr.RESOURCE_SHORTAGE,i&&i("Automatic rejection of incoming channel open: no channels available")),w!==-1),X=b.data;switch(b.type){case"session":if(Xt(this,"session")&&j()){R=()=>{if(N)return;N=!0;let re=new Nn(this,b,w);return this._chanMgr.update(w,re),C.channelOpenConfirm(b.sender,w,er,tr),re},this.emit("session",R,ie);return}break;case"direct-tcpip":if(Xt(this,"tcpip")&&j()){R=()=>{if(N)return;N=!0;let re={type:void 0,incoming:{id:w,window:er,packetSize:tr,state:"open"},outgoing:{id:b.sender,window:b.window,packetSize:b.packetSize,state:"open"}},fe=new Gr(this,re,{server:!0});return this._chanMgr.update(w,fe),C.channelOpenConfirm(b.sender,w,er,tr),fe},this.emit("tcpip",R,ie,X);return}break;case"direct-streamlocal@openssh.com":if(Xt(this,"openssh.streamlocal")&&j()){R=()=>{if(N)return;N=!0;let re={type:void 0,incoming:{id:w,window:er,packetSize:tr,state:"open"},outgoing:{id:b.sender,window:b.window,packetSize:b.packetSize,state:"open"}},fe=new Gr(this,re,{server:!0});return this._chanMgr.update(w,fe),C.channelOpenConfirm(b.sender,w,er,tr),fe},this.emit("openssh.streamlocal",R,ie,X);return}break;default:k=Vr.UNKNOWN_CHANNEL_TYPE,i&&i(`Automatic rejection of unsupported incoming channel open type: ${b.type}`)}k===void 0&&(k=Vr.ADMINISTRATIVELY_PROHIBITED,i&&i(`Automatic rejection of unexpected incoming channel open for: ${b.type}`)),ie()},CHANNEL_OPEN_CONFIRMATION:(v,b)=>{let w=this._chanMgr.get(b.recipient);if(typeof w!="function")return;let k={type:w.type,incoming:{id:b.recipient,window:er,packetSize:tr,state:"open"},outgoing:{id:b.sender,window:b.window,packetSize:b.packetSize,state:"open"}},N=new Gr(this,k,{server:!0});this._chanMgr.update(b.recipient,N),w(void 0,N)},CHANNEL_OPEN_FAILURE:(v,b,w,k)=>{let N=this._chanMgr.get(b);if(typeof N!="function")return;Lg(this,b,{reason:w,description:k},N)},CHANNEL_DATA:(v,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<=Og&&Tg(k)}},CHANNEL_EXTENDED_DATA:(v,b,w,k)=>{},CHANNEL_WINDOW_ADJUST:(v,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:(v,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:(v,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:(v,b,w,k,N)=>{let R=this._chanMgr.get(b);if(typeof R!="object"||R===null)return;let ie=!1,j,X;if(R.constructor!==Nn){k&&C.channelFailure(R.outgoing.id);return}if(k&&(w!=="shell"&&w!=="exec"&&w!=="subsystem"&&(j=()=>{ie||R._ending||R._channel||(ie=!0,C.channelSuccess(R._chanInfo.outgoing.id))}),X=()=>{ie||R._ending||R._channel||(ie=!0,C.channelFailure(R._chanInfo.outgoing.id))}),R._ending){X&&X();return}switch(w){case"env":if(Xt(R,"env")){R.emit("env",j,X,{key:N.name,val:N.value});return}break;case"pty-req":if(Xt(R,"pty")){R.emit("pty",j,X,N);return}break;case"window-change":Xt(R,"window-change")?R.emit("window-change",j,X,N):X&&X();break;case"x11-req":if(Xt(R,"x11")){R.emit("x11",j,X,N);return}break;case"signal":if(Xt(R,"signal")){R.emit("signal",j,X,{name:N});return}break;case"auth-agent-req@openssh.com":if(Xt(R,"auth-agent")){R.emit("auth-agent",j,X);return}break;case"shell":if(Xt(R,"shell")){j=()=>{if(ie||R._ending||R._channel)return;ie=!0,k&&C.channelSuccess(R._chanInfo.outgoing.id);let re=new Gr(this,R._chanInfo,{server:!0});return re.subtype=R.subtype=w,R._channel=re,re},R.emit("shell",j,X);return}break;case"exec":if(Xt(R,"exec")){j=()=>{if(ie||R._ending||R._channel)return;ie=!0,k&&C.channelSuccess(R._chanInfo.outgoing.id);let re=new Gr(this,R._chanInfo,{server:!0});return re.subtype=R.subtype=w,R._channel=re,re},R.emit("exec",j,X,{command:N});return}break;case"subsystem":{let re=N==="sftp";if(j=()=>{if(ie||R._ending||R._channel)return;ie=!0,k&&C.channelSuccess(R._chanInfo.outgoing.id);let fe;return re?fe=new Rg(this,R._chanInfo,{server:!0,debug:i}):(fe=new Gr(this,R._chanInfo,{server:!0}),fe.subtype=R.subtype=`${w}:${N}`),R._channel=fe,fe},N==="sftp"){if(Xt(R,"sftp")){R.emit("sftp",j,X);return}re=!1}if(Xt(R,"subsystem")){R.emit("subsystem",j,X,{name:N});return}break}}i&&i(`Automatic rejection of incoming channel request: ${w}`),X&&X()},CHANNEL_EOF:(v,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:(v,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)||Dg(this,b,w)},SERVICE_REQUEST:(v,b)=>{if(c===0||l||this.authenticated||b!=="ssh-userauth"){C.disconnect(zr.SERVICE_NOT_AVAILABLE),t.end();return}l=!0,C.serviceAccept(b)},USERAUTH_REQUEST:(v,b,w,k,N)=>{if(c===0||this.authenticated||f&&(f.username!==b||f.service!==w)||k!=="password"&&k!=="publickey"&&k!=="hostbased"&&k!=="keyboard-interactive"&&k!=="none"||u.length===Ug){C.disconnect(zr.PROTOCOL_ERROR),t.end();return}else if(w!=="ssh-connection"){C.disconnect(zr.SERVICE_NOT_AVAILABLE),t.end();return}let R;switch(k){case"keyboard-interactive":R=new Fs(C,b,w,k,N,$);break;case"publickey":R=new nc(C,b,w,k,N,$);break;case"hostbased":R=new rc(C,b,w,k,N,$);break;case"password":if(f&&f instanceof Hs&&f._changeCb){let ie=f._changeCb;f._changeCb=void 0,ie(N.newPassword);return}R=new Hs(C,b,w,k,N,$);break;case"none":R=new nr(C,b,w,k,$);break}if(f)if(f._initialResponse)f._multistep&&!f._finalResponse&&(f._cleanup&&f._cleanup(),f.emit("abort"));else return u.push(R);f=R,Xt(this,"authentication")?this.emit("authentication",f):f.reject()},USERAUTH_INFO_RESPONSE:(v,b)=>{f&&f instanceof Fs&&f._onInfoResponse(b)},GLOBAL_REQUEST:(v,b,w,k)=>{let N={type:null,buf:null};function R(ie,j){N.type=ie,N.buf=j,F()}if(w&&y.push(N),(b==="tcpip-forward"||b==="cancel-tcpip-forward"||b==="no-more-sessions@openssh.com"||b==="streamlocal-forward@openssh.com"||b==="cancel-streamlocal-forward@openssh.com")&&Xt(this,"request")&&this.authenticated){let ie,j;if(w){let X=!1;ie=re=>{if(X)return;X=!0;let fe;b==="tcpip-forward"&&k.bindPort===0&&typeof re=="number"&&(fe=Buffer.allocUnsafe(4),Pg(fe,re,0)),R("SUCCESS",fe)},j=()=>{X||(X=!0,R("FAILURE"))}}if(b==="no-more-sessions@openssh.com"){this.noMoreSessions=!0,ie&&ie();return}this.emit("request",ie,j,b,k)}else w&&R("FAILURE")}}});t.pause(),vg.then(()=>{C.start(),t.on("data",v=>{try{C.parse(v,0,v.length)}catch(b){this.emit("error",b);try{$s(t)&&t.end()}catch{}}}),t.resume()}).catch(v=>{this.emit("error",v);try{$s(t)&&t.end()}catch{}}),t.on("error",v=>{v.level="socket",this.emit("error",v)}).once("end",()=>{i&&i("Socket ended"),C.cleanup(),this.emit("end")}).once("close",()=>{i&&i("Socket closed"),C.cleanup(),this.emit("close");let v=new Error("No response from server");this._chanMgr.cleanup(v)});let $=(v,b,w,k)=>{f===v&&!this.authenticated&&(b?(f=void 0,this.authenticated=!0,C.authSuccess(),u=[],this.emit("ready")):(C.authFailure(w,k),u.length&&(f=u.pop(),Xt(this,"authentication")?this.emit("authentication",f):f.reject())))};function F(){for(;y.length>0&&y[0].type;){let v=y.shift();v.type==="SUCCESS"&&C.requestSuccess(v.buf),v.type==="FAILURE"&&C.requestFailure()}}}end(){return this._sock&&$s(this._sock)&&(this._protocol.disconnect(zr.BY_APPLICATION),this._sock.end()),this}x11(t,e,r){return tc(this,"x11",{originAddr:t,originPort:e},r),this}forwardOut(t,e,r,s,i){return tc(this,"forwarded-tcpip",{boundAddr:t,boundPort:e,remoteAddr:r,remotePort:s},i),this}openssh_forwardOutStreamLocal(t,e){return tc(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 tc(n,t,e,r){let s=er,i=tr;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 $g(n,t){return n-t}ic.exports=dn;ic.exports.IncomingClient=Qs});var ff=lt((xE,uf)=>{"use strict";var{createCipheriv:Fg,generateKeyPair:Hg,generateKeyPairSync:Qg,getCurves:Wg,randomBytes:af}=require("crypto"),{Ber:St}=li(),qg=xo().pbkdf,{CIPHER_INFO:Kg}=Gn(),Vg=16,zg=16,Gg=Wg(),Yg=new Map(Object.entries(Kg));function cf(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(!Gg.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 jg(n,t,e){switch(n){case"rsa":{let r=new St.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()!==St.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 St.Reader(r.readString(St.OctetString,!0)),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in RSA private key");let s=r.readString(St.Integer,!0),i=r.readString(St.Integer,!0),o=r.readString(St.Integer,!0),a=r.readString(St.Integer,!0),c=r.readString(St.Integer,!0);r.readString(St.Integer,!0),r.readString(St.Integer,!0);let l=r.readString(St.Integer,!0),u=Buffer.from("ssh-rsa"),f=Buffer.allocUnsafe(4+u.length+4+s.length+4+i.length+4+o.length+4+l.length+4+a.length+4+c.length),h=0;f.writeUInt32BE(u.length,h+=0),f.set(u,h+=4),f.writeUInt32BE(s.length,h+=u.length),f.set(s,h+=4),f.writeUInt32BE(i.length,h+=s.length),f.set(i,h+=4),f.writeUInt32BE(o.length,h+=i.length),f.set(o,h+=4),f.writeUInt32BE(l.length,h+=o.length),f.set(l,h+=4),f.writeUInt32BE(a.length,h+=l.length),f.set(a,h+=4),f.writeUInt32BE(c.length,h+=a.length),f.set(c,h+=4);let p=Buffer.allocUnsafe(4+u.length+4+i.length+4+s.length);return h=0,p.writeUInt32BE(u.length,h+=0),p.set(u,h+=4),p.writeUInt32BE(i.length,h+=u.length),p.set(i,h+=4),p.writeUInt32BE(s.length,h+=i.length),p.set(s,h+=4),{sshName:u.toString(),priv:f,pub:p}}case"ec":{let r=new St.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(St.BitString,!0);{let h=0;for(;h<s.length&&s[h]===0;++h);h>0&&(s=s.slice(h))}if(r=new St.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 St.Reader(r.readString(St.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(St.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),u=0;l.writeUInt32BE(c.length,u+=0),l.set(c,u+=4),l.writeUInt32BE(o.length,u+=c.length),l.set(o,u+=4),l.writeUInt32BE(s.length,u+=o.length),l.set(s,u+=4),l.writeUInt32BE(a.length,u+=s.length),l.set(a,u+=4);let f=Buffer.allocUnsafe(4+c.length+4+o.length+4+s.length);return u=0,f.writeUInt32BE(c.length,u+=0),f.set(c,u+=4),f.writeUInt32BE(o.length,u+=c.length),f.set(o,u+=4),f.writeUInt32BE(s.length,u+=o.length),f.set(s,u+=4),{sshName:c.toString(),priv:l,pub:f}}case"ed25519":{let r=new St.Reader(t);if(r.readSequence(),r.readSequence(),r.readOID()!=="1.3.101.112")throw new Error("Bad ED25519 public OID");let s=r.readString(St.BitString,!0);{let u=0;for(;u<s.length&&s[u]===0;++u);u>0&&(s=s.slice(u))}if(r=new St.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 St.Reader(r.readString(St.OctetString,!0));let i=r.readString(St.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 lf(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=Yg.get(r.cipher);if(c===void 0)throw new Error("Invalid cipher name");if(s==="new"){let l=zg;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 u=Buffer.allocUnsafe(c.keyLen+c.ivLen),f=af(Vg);if(qg(a,a.length,f,f.length,u,u.length,l)!==0)return new Error("Failed to generate information to encrypt key");let p=Buffer.allocUnsafe(4+f.length+4);{let y=0;p.writeUInt32BE(f.length,y+=0),p.set(f,y+=4),p.writeUInt32BE(l,y+=f.length)}i={cipher:c,cipherName:r.cipher,kdfName:"bcrypt",kdfOptions:p,key:u.slice(0,c.keyLen),iv:u.slice(c.keyLen)}}}switch(s){case"new":{let a=`-----BEGIN OPENSSH PRIVATE KEY-----
16
- `,c,l=Buffer.from(i?i.cipherName:"none"),u=Buffer.from(i?i.kdfName:"none"),f=i?i.kdfOptions:Buffer.alloc(0),h=i?i.cipher.blockLen:8,p=jg(n,t,e),y=af(4),E=Buffer.from(o),S=8+p.priv.length+4+E.length,x=[];for(let F=1;(S+x.length)%h;++F)x.push(F&255);x=Buffer.from(x);let P=Buffer.allocUnsafe(S+x.length),q;{let F=0;P.set(y,F+=0),P.set(y,F+=4),P.set(p.priv,F+=4),P.writeUInt32BE(E.length,F+=p.priv.length),P.set(E,F+=4),P.set(x,F+=E.length)}if(i){let F={authTagLength:i.cipher.authLen},v=Fg(i.cipher.sslName,i.key,i.iv,F);v.setAutoPadding(!1),P=Buffer.concat([v.update(P),v.final()]),i.cipher.authLen>0?q=v.getAuthTag():q=Buffer.alloc(0),i.key.fill(0),i.iv.fill(0)}else q=Buffer.alloc(0);let C=Buffer.from("openssh-key-v1\0"),$=Buffer.allocUnsafe(C.length+4+l.length+4+u.length+4+f.length+4+4+p.pub.length+4+P.length+q.length);{let F=0;$.set(C,F+=0),$.writeUInt32BE(l.length,F+=C.length),$.set(l,F+=4),$.writeUInt32BE(u.length,F+=l.length),$.set(u,F+=4),$.writeUInt32BE(f.length,F+=u.length),$.set(f,F+=4),$.writeUInt32BE(1,F+=f.length),$.writeUInt32BE(p.pub.length,F+=4),$.set(p.pub,F+=4),$.writeUInt32BE(P.length,F+=p.pub.length),$.set(P,F+=4),$.set(q,F+=P.length)}{let F=$.base64Slice(0,$.length),v=F.replace(/.{64}/g,`$&
15
+ ${e}`}};var Am=2**32,pu=(()=>{try{return new Function("return 2n ** 32n")()}catch{}})();vi.ERR_OUT_OF_RANGE=class gu extends RangeError{constructor(t,e,r,i){super(),Error.captureStackTrace(this,gu),Bs(e,'Missing "range" argument');let s=i?t:`The value of "${t}" is out of range.`,o;Number.isInteger(r)&&Math.abs(r)>Am?o=du(String(r)):typeof r=="bigint"?(o=String(r),(r>pu||r<-pu)&&(o=du(o)),o+="n"):o=gm(r),s+=` It must be ${e}. Received ${o}`,this.message=s}};var Rs=class n extends TypeError{constructor(t,e,r){super(),Error.captureStackTrace(this,n),Bs(typeof t=="string","'name' must be a string");let i;typeof e=="string"&&e.startsWith("not ")?(i="must not be",e=e.replace(/^not /,"")):i="must be";let s;if(t.endsWith(" argument"))s=`The ${t} ${i} ${hu(e,"type")}`;else{let o=t.includes(".")?"property":"argument";s=`The "${t}" ${o} ${i} ${hu(e,"type")}`}s+=`. Received type ${typeof r}`,this.message=s}};vi.ERR_INVALID_ARG_TYPE=Rs;vi.validateNumber=function(t,e){if(typeof t!="number")throw new Rs(e,"number",t)}});var Ni=lt((_E,Bu)=>{"use strict";var ym=require("events"),Zn=require("fs"),{constants:sn}=Zn,{Readable:xu,Writable:Da}=require("stream"),{inherits:wu,types:{isDate:Ra}}=require("util"),Em=Buffer[Symbol.species],{bufferCopy:Jn,bufferSlice:Kr,makeBufferParser:_m,writeUInt32BE:G}=En(),Hn={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},bm=new Map(Object.values(nt).map(n=>[n,1])),Sm={[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},on={VERSION:2,STATUS:101,HANDLE:102,DATA:103,NAME:104,ATTRS:105,EXTENDED:201},ke={READ:1,WRITE:2,APPEND:4,CREAT:8,TRUNC:16,EXCL:32},yu=2*1024,pt=2**32-1,xm=Buffer.from([0,0,0,5,Be.INIT,0,0,0,3]),wm=Buffer.from([0,0,0,5,on.VERSION,0,0,0,3]),Im=/^SSH-2.0-(?:OpenSSH|dropbear)/,Na=256*1024,Q=_m(),Cm={readable:!1,writable:!1,push:n=>{},once:()=>{},on:()=>{},emit:()=>{},end:()=>{}};function Iu(){}var Pa=class extends ym{constructor(t,e,r){super(),(typeof r!="object"||!r)&&(r={});let i=t._protocol._remoteIdentRaw;this.server=!!r.server,this._debug=typeof r.debug=="function"?r.debug:void 0,this._isOpenSSH=i&&Im.test(i),this._version=-1,this._extensions={},this._biOpt=r.biOpt,this._pktLenBytes=0,this._pktLen=0,this._pktPos=0,this._pktType=0,this._pktData=void 0,this._writeReqid=-1,this._requests={},this._maxInPktLen=Na,this._maxOutPktLen=34e3,this._maxReadLen=(this._isOpenSSH?Na:34e3)-yu,this._maxWriteLen=(this._isOpenSSH?Na:34e3)-yu,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=Cm,this.readable=!0}push(t){if(t===null){if(Nu(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 at(this,"Invalid packet length");if(this._pktLen>this._maxInPktLen){let a=this._maxInPktLen;return at(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 Em(t.buffer,t.byteOffset+e,o):(this._pkt||(this._pkt=Buffer.allocUnsafe(this._pktLen)),this._pkt.set(new Uint8Array(t.buffer,t.byteOffset+e,o),this._pktPos)):o===this._pktLen?this._pkt=t:(this._pkt||(this._pkt=Buffer.allocUnsafe(this._pktLen)),this._pkt.set(t,this._pktPos)),e+=o,this._pktPos+=o,this._pktPos<this._pktLen)return}let r=this._pkt[0],i=this._pkt;this._pktLen=0,this._pktLenBytes=0,this._pkt=void 0,this._pktPos=0;let s=this.server?Rm[r]:Bm[r];if(!s)return at(this,`Unknown packet type ${r}`);if(this._version===-1){if(this.server){if(r!==Be.INIT)return at(this,`Expected INIT packet, got ${r}`)}else if(r!==on.VERSION)return at(this,`Expected VERSION packet, got ${r}`)}if(s(this,i)===!1)return}}end(){this.destroy()}destroy(){(this.outgoing.state==="open"||this.outgoing.state==="eof")&&(this.outgoing.state="closing",this._protocol.channelClose(this.outgoing.id))}_init(){this._init=Iu,this.server||Ze(this,xm)}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 yn(this,t,e)}open(t,e,r,i){if(this.server)throw new Error("Client-only method called in server mode");typeof r=="function"&&(i=r,r=void 0);let s=typeof e=="number"?e:ku(e);if(s===null)throw new Error(`Unknown flags string: ${e}`);let o=0,a=0;(typeof r=="string"||typeof r=="number")&&(r={mode:r}),typeof r=="object"&&r!==null&&(r=Ar(r),o=r.flags,a=r.nb);let c=Buffer.byteLength(t),l=9,u=Buffer.allocUnsafe(13+c+4+4+a);G(u,u.length-4,0),u[4]=Be.OPEN;let f=this._writeReqid=this._writeReqid+1&pt;G(u,f,5),G(u,c,l),u.utf8Write(t,l+=4,c),G(u,s,l+=c),G(u,o,l+=4),a&&(l+=4,a===Pe.length?u.set(Pe,l):Jn(Pe,u,0,a,l),l+=a),this._requests[f]={cb:i};let h=Ze(this,u);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,i=9,s=Buffer.allocUnsafe(13+r);G(s,s.length-4,0),s[4]=Be.CLOSE;let o=this._writeReqid=this._writeReqid+1&pt;G(s,o,5),G(s,r,i),s.set(t,i+=4),this._requests[o]={cb:e};let a=Ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} CLOSE`)}read(t,e,r,i,s,o){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");if(!Buffer.isBuffer(e))throw new Error("buffer is not a Buffer");if(r>=e.length)throw new Error("offset is out of bounds");if(r+i>e.length)throw new Error("length extends beyond buffer");if(s===null)throw new Error("null position currently unsupported");Cu(this,t,e,r,i,s,o)}readData(t,e,r,i,s,o){this.read(t,e,r,i,s,o)}write(t,e,r,i,s,o){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");if(!Buffer.isBuffer(e))throw new Error("buffer is not a Buffer");if(r>e.length)throw new Error("offset is out of bounds");if(r+i>e.length)throw new Error("length extends beyond buffer");if(s===null)throw new Error("null position currently unsupported");if(!i){o&&process.nextTick(o,void 0,0);return}let a=this._maxWriteLen,c=Math.max(i-a,0),l=s;c&&(i=a);let u=t.length,f=9,h=Buffer.allocUnsafe(13+u+8+4+i);G(h,h.length-4,0),h[4]=Be.WRITE;let p=this._writeReqid=this._writeReqid+1&pt;G(h,p,5),G(h,u,f),h.set(t,f+=4),f+=u;for(let E=7;E>=0;--E)h[f+E]=s&255,s/=256;G(h,i,f+=8),Jn(e,h,r,r+i,f+=4),this._requests[p]={cb:E=>{E?typeof o=="function"&&o(E):c?this.write(t,e,r+i,c,l+i,o):typeof o=="function"&&o(void 0,r+i)}};let y=Ze(this,h);if(this._debug){let E=y?"Sent":"Buffered";this._debug(`SFTP: Outbound: ${E} WRITE (id:${p})`)}}writeData(t,e,r,i,s,o){this.write(t,e,r,i,s,o)}fastGet(t,e,r,i){if(this.server)throw new Error("Client-only method called in server mode");Eu(this,Zn,t,e,r,i)}fastPut(t,e,r,i){if(this.server)throw new Error("Client-only method called in server mode");Eu(Zn,this,t,e,r,i)}readFile(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let i;if(typeof r=="function"?i=r:typeof e=="function"&&(i=e,e=void 0),typeof e=="string")e={encoding:e,flag:"r"};else if(!e)e={encoding:null,flag:"r"};else if(typeof e!="object")throw new TypeError("Bad arguments");let s=e.encoding;if(s&&!Buffer.isEncoding(s))throw new Error(`Unknown encoding: ${s}`);let o,a,c,l=0,u,f=0,h=e.flag||"r",p=()=>{o===0?(a=Buffer.allocUnsafe(8192),this.read(u,a,0,8192,f,y)):this.read(u,a,l,o-l,f,y)},y=(S,x)=>{let P;if(S){if(P=S.code===nt.EOF,!P)return this.close(u,()=>i&&i(S))}else P=!1;if(P||o===0&&x===0)return E();f+=x,l+=x,o!==0?l===o?E():p():(c.push(Kr(a,0,x)),p())};y._wantEOFError=!0;let E=()=>{this.close(u,S=>(o===0?a=Buffer.concat(c,l):l<o&&(a=Kr(a,0,l)),s&&(a=a.toString(s)),i&&i(S,a)))};this.open(t,h,438,(S,x)=>{if(S)return i&&i(S);u=x;let P=(q,C)=>{if(q){this.stat(t,($,F)=>{if($)return this.close(u,()=>{i&&i(q)});P(null,F)});return}if(o=C.size||0,o===0)return c=[],p();a=Buffer.allocUnsafe(o),p()};this.fstat(u,P)})}writeFile(t,e,r,i){if(this.server)throw new Error("Client-only method called in server mode");let s;if(typeof i=="function"?s=i:typeof r=="function"&&(s=r,r=void 0),typeof r=="string")r={encoding:r,mode:438,flag:"w"};else if(!r)r={encoding:"utf8",mode:438,flag:"w"};else if(typeof r!="object")throw new TypeError("Bad arguments");if(r.encoding&&!Buffer.isEncoding(r.encoding))throw new Error(`Unknown encoding: ${r.encoding}`);let o=r.flag||"w";this.open(t,o,r.mode,(a,c)=>{if(a)s&&s(a);else{let l=Buffer.isBuffer(e)?e:Buffer.from(""+e,r.encoding||"utf8"),u=/a/.test(o)?null:0;if(u===null){let f=(h,p)=>{if(h){this.stat(t,(y,E)=>{if(y)return this.close(c,()=>{s&&s(h)});f(null,E)});return}Ta(this,c,l,0,l.length,p.size,s)};this.fstat(c,f);return}Ta(this,c,l,0,l.length,u,s)}})}appendFile(t,e,r,i){if(this.server)throw new Error("Client-only method called in server mode");let s;if(typeof i=="function"?s=i:typeof r=="function"&&(s=r,r=void 0),typeof r=="string")r={encoding:r,mode:438,flag:"a"};else if(!r)r={encoding:"utf8",mode:438,flag:"a"};else if(typeof r!="object")throw new TypeError("Bad arguments");r.flag||(r=Object.assign({flag:"a"},r)),this.writeFile(t,e,r,s)}exists(t,e){if(this.server)throw new Error("Client-only method called in server mode");this.stat(t,r=>{e&&e(!r)})}unlink(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+r);G(s,s.length-4,0),s[4]=Be.REMOVE;let o=this._writeReqid=this._writeReqid+1&pt;G(s,o,5),G(s,r,i),s.utf8Write(t,i+=4,r),this._requests[o]={cb:e};let a=Ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} REMOVE`)}rename(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(t),s=Buffer.byteLength(e),o=9,a=Buffer.allocUnsafe(13+i+4+s);G(a,a.length-4,0),a[4]=Be.RENAME;let c=this._writeReqid=this._writeReqid+1&pt;G(a,c,5),G(a,i,o),a.utf8Write(t,o+=4,i),G(a,s,o+=i),a.utf8Write(e,o+=4,s),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 i=0,s=0;typeof e=="function"&&(r=e,e=void 0),typeof e=="object"&&e!==null&&(e=Ar(e),i=e.flags,s=e.nb);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+s);G(c,c.length-4,0),c[4]=Be.MKDIR;let l=this._writeReqid=this._writeReqid+1&pt;G(c,l,5),G(c,o,a),c.utf8Write(t,a+=4,o),G(c,i,a+=o),s&&(a+=4,s===Pe.length?c.set(Pe,a):Jn(Pe,c,0,s,a),a+=s),this._requests[l]={cb:r};let u=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${u?"Buffered":"Sending"} MKDIR`)}rmdir(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+r);G(s,s.length-4,0),s[4]=Be.RMDIR;let o=this._writeReqid=this._writeReqid+1&pt;G(s,o,5),G(s,r,i),s.utf8Write(t,i+=4,r),this._requests[o]={cb:e};let a=Ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} RMDIR`)}readdir(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");typeof e=="function"&&(r=e,e={}),(typeof e!="object"||e===null)&&(e={});let i=!(e&&e.full);if(!Buffer.isBuffer(t)&&typeof t!="string")throw new Error("missing directory handle or path");if(typeof t=="string"){let u=[],f=0,h=(p,y)=>{if(p)return r(p);this.readdir(y,e,(E,S)=>{let x=E&&E.code===nt.EOF;if(E&&!x)return this.close(y,()=>r(E));if(x)return this.close(y,P=>{if(P)return r(P);r(void 0,u)});for(let P=0;P<S.length;++P,++f)u[f]=S[P];h(void 0,y)})};return this.opendir(t,h)}let s=t.length,o=9,a=Buffer.allocUnsafe(13+s);G(a,a.length-4,0),a[4]=Be.READDIR;let c=this._writeReqid=this._writeReqid+1&pt;G(a,c,5),G(a,s,o),a.set(t,o+=4),this._requests[c]={cb:i?(u,f)=>{if(typeof r=="function"){if(u)return r(u);for(let h=f.length-1;h>=0;--h)(f[h].filename==="."||f[h].filename==="..")&&f.splice(h,1);r(void 0,f)}}: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,i=9,s=Buffer.allocUnsafe(13+r);G(s,s.length-4,0),s[4]=Be.FSTAT;let o=this._writeReqid=this._writeReqid+1&pt;G(s,o,5),G(s,r,i),s.set(t,i+=4),this._requests[o]={cb:e};let a=Ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} FSTAT`)}stat(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+r);G(s,s.length-4,0),s[4]=Be.STAT;let o=this._writeReqid=this._writeReqid+1&pt;G(s,o,5),G(s,r,i),s.utf8Write(t,i+=4,r),this._requests[o]={cb:e};let a=Ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} STAT`)}lstat(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+r);G(s,s.length-4,0),s[4]=Be.LSTAT;let o=this._writeReqid=this._writeReqid+1&pt;G(s,o,5),G(s,r,i),s.utf8Write(t,i+=4,r),this._requests[o]={cb:e};let a=Ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} LSTAT`)}opendir(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+r);G(s,s.length-4,0),s[4]=Be.OPENDIR;let o=this._writeReqid=this._writeReqid+1&pt;G(s,o,5),G(s,r,i),s.utf8Write(t,i+=4,r),this._requests[o]={cb:e};let a=Ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} OPENDIR`)}setstat(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let i=0,s=0;typeof e=="object"&&e!==null?(e=Ar(e),i=e.flags,s=e.nb):typeof e=="function"&&(r=e);let o=Buffer.byteLength(t),a=9,c=Buffer.allocUnsafe(13+o+4+s);G(c,c.length-4,0),c[4]=Be.SETSTAT;let l=this._writeReqid=this._writeReqid+1&pt;G(c,l,5),G(c,o,a),c.utf8Write(t,a+=4,o),G(c,i,a+=o),s&&(a+=4,s===Pe.length?c.set(Pe,a):Jn(Pe,c,0,s,a),a+=s),this._requests[l]={cb:r};let u=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${u?"Buffered":"Sending"} SETSTAT`)}fsetstat(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let i=0,s=0;typeof e=="object"&&e!==null?(e=Ar(e),i=e.flags,s=e.nb):typeof e=="function"&&(r=e);let o=t.length,a=9,c=Buffer.allocUnsafe(13+o+4+s);G(c,c.length-4,0),c[4]=Be.FSETSTAT;let l=this._writeReqid=this._writeReqid+1&pt;G(c,l,5),G(c,o,a),c.set(t,a+=4),G(c,i,a+=o),s&&(a+=4,s===Pe.length?c.set(Pe,a):Jn(Pe,c,0,s,a),a+=s),this._requests[l]={cb:r};let u=Ze(this,c);this._debug&&this._debug(`SFTP: Outbound: ${u?"Buffered":"Sending"} FSETSTAT`)}futimes(t,e,r,i){return this.fsetstat(t,{atime:Wr(e),mtime:Wr(r)},i)}utimes(t,e,r,i){return this.setstat(t,{atime:Wr(e),mtime:Wr(r)},i)}fchown(t,e,r,i){return this.fsetstat(t,{uid:e,gid:r},i)}chown(t,e,r,i){return this.setstat(t,{uid:e,gid:r},i)}fchmod(t,e,r){return this.fsetstat(t,{mode:e},r)}chmod(t,e,r){return this.setstat(t,{mode:e},r)}readlink(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=Buffer.byteLength(t),i=9,s=Buffer.allocUnsafe(13+r);G(s,s.length-4,0),s[4]=Be.READLINK;let o=this._writeReqid=this._writeReqid+1&pt;G(s,o,5),G(s,r,i),s.utf8Write(t,i+=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,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} READLINK`)}symlink(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let i=Buffer.byteLength(e),s=Buffer.byteLength(t),o=9,a=Buffer.allocUnsafe(13+i+4+s);G(a,a.length-4,0),a[4]=Be.SYMLINK;let c=this._writeReqid=this._writeReqid+1&pt;G(a,c,5),this._isOpenSSH?(G(a,s,o),a.utf8Write(t,o+=4,s),G(a,i,o+=s),a.utf8Write(e,o+=4,i)):(G(a,i,o),a.utf8Write(e,o+=4,i),G(a,s,o+=i),a.utf8Write(t,o+=4,s)),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),i=9,s=Buffer.allocUnsafe(13+r);G(s,s.length-4,0),s[4]=Be.REALPATH;let o=this._writeReqid=this._writeReqid+1&pt;G(s,o,5),G(s,r,i),s.utf8Write(t,i+=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,s);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} REALPATH`)}ext_openssh_rename(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");let i=this._extensions["posix-rename@openssh.com"];if(!i||i!=="1")throw new Error("Server does not support this extended request");let s=Buffer.byteLength(t),o=Buffer.byteLength(e),a=9,c=Buffer.allocUnsafe(41+s+4+o);G(c,c.length-4,0),c[4]=Be.EXTENDED;let l=this._writeReqid=this._writeReqid+1&pt;G(c,l,5),G(c,24,a),c.utf8Write("posix-rename@openssh.com",a+=4,24),G(c,s,a+=24),c.utf8Write(t,a+=4,s),G(c,o,a+=s),c.utf8Write(e,a+=4,o),this._requests[l]={cb:r};let u=Ze(this,c);if(this._debug){let f=u?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} posix-rename@openssh.com`)}}ext_openssh_statvfs(t,e){if(this.server)throw new Error("Client-only method called in server mode");let r=this._extensions["statvfs@openssh.com"];if(!r||r!=="2")throw new Error("Server does not support this extended request");let i=Buffer.byteLength(t),s=9,o=Buffer.allocUnsafe(36+i);G(o,o.length-4,0),o[4]=Be.EXTENDED;let a=this._writeReqid=this._writeReqid+1&pt;G(o,a,5),G(o,19,s),o.utf8Write("statvfs@openssh.com",s+=4,19),G(o,i,s+=19),o.utf8Write(t,s+=4,i),this._requests[a]={extended:"statvfs@openssh.com",cb:e};let c=Ze(this,o);if(this._debug){let 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 i=t.length,s=9,o=Buffer.allocUnsafe(37+i);G(o,o.length-4,0),o[4]=Be.EXTENDED;let a=this._writeReqid=this._writeReqid+1&pt;G(o,a,5),G(o,20,s),o.utf8Write("fstatvfs@openssh.com",s+=4,20),G(o,i,s+=20),o.set(t,s+=4),this._requests[a]={extended:"fstatvfs@openssh.com",cb:e};let c=Ze(this,o);if(this._debug){let 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 s=Buffer.byteLength(t),o=Buffer.byteLength(e),a=9,c=Buffer.allocUnsafe(37+s+4+o);G(c,c.length-4,0),c[4]=Be.EXTENDED;let l=this._writeReqid=this._writeReqid+1&pt;G(c,l,5),G(c,20,a),c.utf8Write("hardlink@openssh.com",a+=4,20),G(c,s,a+=20),c.utf8Write(t,a+=4,s),G(c,o,a+=s),c.utf8Write(e,a+=4,o),this._requests[l]={cb:r};let u=Ze(this,c);if(this._debug){let f=u?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${f} hardlink@openssh.com`)}}ext_openssh_fsync(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["fsync@openssh.com"]!=="1")throw new Error("Server does not support this extended request");if(!Buffer.isBuffer(t))throw new Error("handle is not a Buffer");let i=t.length,s=9,o=Buffer.allocUnsafe(34+i);G(o,o.length-4,0),o[4]=Be.EXTENDED;let a=this._writeReqid=this._writeReqid+1&pt;G(o,a,5),G(o,17,s),o.utf8Write("fsync@openssh.com",s+=4,17),G(o,i,s+=17),o.set(t,s+=4),this._requests[a]={cb:e};let c=Ze(this,o);this._debug&&this._debug(`SFTP: Outbound: ${c?"Buffered":"Sending"} fsync@openssh.com`)}ext_openssh_lsetstat(t,e,r){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["lsetstat@openssh.com"]!=="1")throw new Error("Server does not support this extended request");let s=0,o=0;typeof e=="object"&&e!==null?(e=Ar(e),s=e.flags,o=e.nb):typeof e=="function"&&(r=e);let a=Buffer.byteLength(t),c=9,l=Buffer.allocUnsafe(37+a+4+o);G(l,l.length-4,0),l[4]=Be.EXTENDED;let u=this._writeReqid=this._writeReqid+1&pt;G(l,u,5),G(l,20,c),l.utf8Write("lsetstat@openssh.com",c+=4,20),G(l,a,c+=20),l.utf8Write(t,c+=4,a),G(l,s,c+=a),o&&(c+=4,o===Pe.length?l.set(Pe,c):Jn(Pe,l,0,o,c),c+=o),this._requests[u]={cb:r};let f=Ze(this,l);if(this._debug){let h=f?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${h} lsetstat@openssh.com`)}}ext_openssh_expandPath(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["expand-path@openssh.com"]!=="1")throw new Error("Server does not support this extended request");let i=Buffer.byteLength(t),s=9,o=Buffer.allocUnsafe(40+i);G(o,o.length-4,0),o[4]=Be.EXTENDED;let a=this._writeReqid=this._writeReqid+1&pt;G(o,a,5),G(o,23,s),o.utf8Write("expand-path@openssh.com",s+=4,23),G(o,i,s+=20),o.utf8Write(t,s+=4,i),this._requests[a]={cb:(l,u)=>{if(typeof e=="function"){if(l)return e(l);if(!u||!u.length)return e(new Error("Response missing expanded path"));e(void 0,u[0].filename)}}};let c=Ze(this,o);if(this._debug){let l=c?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${l} expand-path@openssh.com`)}}ext_copy_data(t,e,r,i,s,o){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["copy-data"]!=="1")throw new Error("Server does not support this extended request");if(!Buffer.isBuffer(t))throw new Error("Source handle is not a Buffer");if(!Buffer.isBuffer(i))throw new Error("Destination handle is not a Buffer");let c=0,l=Buffer.allocUnsafe(26+t.length+8+8+4+i.length+8);G(l,l.length-4,c),c+=4,l[c]=Be.EXTENDED,++c;let u=this._writeReqid=this._writeReqid+1&pt;G(l,u,c),c+=4,G(l,9,c),c+=4,l.utf8Write("copy-data",c,9),c+=9,G(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,G(l,i.length,c),c+=4,l.set(i,c),c+=i.length;for(let h=7;h>=0;--h)l[c+h]=s&255,s/=256;this._requests[u]={cb:o};let f=Ze(this,l);if(this._debug){let h=f?"Buffered":"Sending";this._debug(`SFTP: Outbound: ${h} copy-data`)}}ext_home_dir(t,e){if(this.server)throw new Error("Client-only method called in server mode");if(this._extensions["home-directory"]!=="1")throw new Error("Server does not support this extended request");if(typeof t!="string")throw new TypeError("username is not a string");let i=0,s=Buffer.byteLength(t),o=Buffer.allocUnsafe(31+s);G(o,o.length-4,i),i+=4,o[i]=Be.EXTENDED,++i;let a=this._writeReqid=this._writeReqid+1&pt;G(o,a,i),i+=4,G(o,14,i),i+=4,o.utf8Write("home-directory",i,14),i+=14,G(o,s,i),i+=4,o.utf8Write(t,i,s),i+=s,this._requests[a]={cb:(l,u)=>{if(typeof e=="function"){if(l)return e(l);if(!u||!u.length)return e(new Error("Response missing home directory"));e(void 0,u[0].filename)}}};let c=Ze(this,o);if(this._debug){let 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 s=0,o=Buffer.allocUnsafe(47+4*t.length+4+4*e.length);G(o,o.length-4,s),s+=4,o[s]=Be.EXTENDED,++s;let a=this._writeReqid=this._writeReqid+1&pt;G(o,a,s),s+=4,G(o,30,s),s+=4,o.utf8Write("users-groups-by-id@openssh.com",s,30),s+=30,G(o,4*t.length,s),s+=4;for(let l of t)G(o,l,s),s+=4;G(o,4*e.length,s),s+=4;for(let l of e)G(o,l,s),s+=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 i=9,s=Buffer.allocUnsafe(13+r);G(s,s.length-4,0),s[4]=on.HANDLE,G(s,t,5),G(s,r,i),r&&s.set(e,i+=4);let o=Ze(this,s);this._debug&&this._debug(`SFTP: Outbound: ${o?"Buffered":"Sending"} HANDLE`)}status(t,e,r){if(!this.server)throw new Error("Server-only method called in client mode");if(!bm.has(e))throw new Error(`Bad status code: ${e}`);r||(r="");let i=Buffer.byteLength(r),s=9,o=Buffer.allocUnsafe(17+i+4);G(o,o.length-4,0),o[4]=on.STATUS,G(o,t,5),G(o,e,s),G(o,i,s+=4),s+=4,i&&(o.utf8Write(r,s,i),s+=i),G(o,0,s);let a=Ze(this,o);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} STATUS`)}data(t,e,r){if(!this.server)throw new Error("Server-only method called in client mode");let i=Buffer.isBuffer(e);if(!i&&typeof e!="string")throw new Error("data is not a Buffer or string");let s;!i&&!r&&(r=void 0,s=!0);let o=i?e.length:Buffer.byteLength(e,r),a=9,c=Buffer.allocUnsafe(13+o);G(c,c.length-4,0),c[4]=on.DATA,G(c,t,5),G(c,o,a),o&&(i?c.set(e,a+=4):s?c.utf8Write(e,a+=4,o):c.write(e,a+=4,o,r));let 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,i=0,s,o=[];for(let u=0;u<r;++u){let f=e[u],h=!f||!f.filename||typeof f.filename!="string"?"":f.filename;i+=4+Buffer.byteLength(h);let p=!f||!f.longname||typeof f.longname!="string"?"":f.longname;if(i+=4+Buffer.byteLength(p),typeof f.attrs=="object"&&f.attrs!==null){if(s=Ar(f.attrs),i+=4+s.nb,s.nb){let y;s.nb===Pe.length?y=new Uint8Array(Pe):(y=new Uint8Array(s.nb),Jn(Pe,y,0,s.nb,0)),s.bytes=y}o.push(s)}else i+=4,o.push(null)}let a=9,c=Buffer.allocUnsafe(13+i);G(c,c.length-4,0),c[4]=on.NAME,G(c,t,5),G(c,r,a),a+=4;for(let u=0;u<r;++u){let f=e[u];{let p=!f||!f.filename||typeof f.filename!="string"?"":f.filename,y=Buffer.byteLength(p);G(c,y,a),a+=4,y&&(c.utf8Write(p,a,y),a+=y)}{let p=!f||!f.longname||typeof f.longname!="string"?"":f.longname,y=Buffer.byteLength(p);G(c,y,a),a+=4,y&&(c.utf8Write(p,a,y),a+=y)}let h=o[u];h?(G(c,h.flags,a),a+=4,h.flags&&h.bytes&&(c.set(h.bytes,a),a+=h.nb)):(G(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=Ar(e);let r=e.flags,i=e.nb,s=9,o=Buffer.allocUnsafe(13+i);G(o,o.length-4,0),o[4]=on.ATTRS,G(o,t,5),G(o,r,s),i&&(s+=4,i===Pe.length?o.set(Pe,s):Jn(Pe,o,0,i,s),s+=i);let a=Ze(this,o);this._debug&&this._debug(`SFTP: Outbound: ${a?"Buffered":"Sending"} ATTRS`)}};function km(n){try{return Buffer.allocUnsafe(n)}catch(t){return t}}function Cu(n,t,e,r,i,s,o,a){let c=n._maxReadLen,l=Math.max(i-c,0);l&&(i=c);let u=t.length,f=9,h=s,p=Buffer.allocUnsafe(13+u+8+4);G(p,p.length-4,0),p[4]=Be.READ;let y=n._writeReqid=n._writeReqid+1&pt;G(p,y,5),G(p,u,f),p.set(t,f+=4),f+=u;for(let x=7;x>=0;--x)p[f+x]=h&255,h/=256;G(p,i,f+=8),typeof o!="function"&&(o=Iu);let E=a||{nb:0,position:s,off:r,origOff:r,len:void 0,overflow:void 0,cb:(x,P,q)=>{let C=E.len,$=E.overflow;if(x){if(o._wantEOFError||x.code!==nt.EOF)return o(x)}else{if(q>C)return o(new Error("Received more data than requested"));if(q===C&&$){E.nb+=q,E.position+=q,E.off+=q,Cu(n,t,e,E.off,$,E.position,o,E);return}}q=q||0,E.origOff===0&&e.length===E.nb?P=e:P=Kr(e,E.origOff,E.origOff+E.nb+q),o(void 0,E.nb+q,P,E.position)},buffer:void 0};E.len=i,E.overflow=l,E.buffer=Kr(e,r,r+i),n._requests[y]=E;let S=Ze(n,p);n._debug&&n._debug(`SFTP: Outbound: ${S?"Buffered":"Sending"} READ`)}function Eu(n,t,e,r,i,s){let o=64,a=32768,c,l,u;typeof i=="function"?s=i:typeof i=="object"&&i!==null&&(typeof i.concurrency=="number"&&i.concurrency>0&&!isNaN(i.concurrency)&&(o=i.concurrency),typeof i.chunkSize=="number"&&i.chunkSize>0&&!isNaN(i.chunkSize)&&(a=i.chunkSize),typeof i.fileSize=="number"&&i.fileSize>0&&!isNaN(i.fileSize)&&(u=i.fileSize),typeof i.step=="function"&&(c=i.step),(typeof i.mode=="string"||typeof i.mode=="number")&&(l=Ua(i.mode)));let f,h=0,p=0,y=!1,E,S,x,P=a*o;function q(C){if(y)return;y=!0;let $=0,F;E||S?(F=()=>{--$===0&&s(C)},E&&(n===Zn||n.outgoing.state==="open")&&++$,S&&(t===Zn||t.outgoing.state==="open")&&++$,E&&(n===Zn||n.outgoing.state==="open")&&n.close(E,F),S&&(t===Zn||t.outgoing.state==="open")&&t.close(S,F)):s(C)}n.open(e,"r",(C,$)=>{if(C)return q(C);E=$,u===void 0?n.fstat(E,F):F(null,{size:u});function F(v,b){if(v){if(n!==Zn){n.stat(e,(w,k)=>{if(w)return q(v);F(null,k)});return}return q(v)}f=b.size,t.open(r,"w",(w,k)=>{if(w)return q(w);if(S=k,f<=0)return q();for(;P>f;){if(o===1){P=f;break}P-=a,--o}if(x=km(P),x instanceof Error)return q(x);l!==void 0?t.fchmod(S,l,function X(re){if(re){t.chmod(r,l,fe=>X());return}j()}):j();function N(X,re,fe,H,B,L){if(X)return q(X);B=B||0,t.write(S,x,B,re,H,z);function z(ne){if(ne)return q(ne);if(p+=re,c&&c(p,re,f),re<L)return ie(B,H+re,L-re);if(p===f){t.close(S,oe=>{if(S=void 0,oe)return q(oe);n.close(E,Xe=>{if(E=void 0,Xe)return q(Xe);s()})});return}if(h>=f)return;let de=h+a>f?f-h:a;ie(B,h,de),h+=de}}function R(X,re,fe){return(H,B,L)=>{N(H,B,L,re,X,fe)}}function ie(X,re,fe){n.read(E,x,X,fe,re,R(X,re,fe))}function j(){let X=0,re=0;for(;h<f&&X<o;){let fe=h+a>f?f-h:a;ie(re,h,fe),re+=fe,h+=fe,++X}}})}})}function Ta(n,t,e,r,i,s,o){let a=typeof o=="function"?o:void 0;n.write(t,e,r,i,s,(c,l)=>{if(c)return n.close(t,()=>{a&&a(c)});l===i?n.close(t,a):(r+=l,i-=l,s+=l,Ta(n,t,e,r,i,s,a))})}var Ts=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&sn.S_IFMT)===sn.S_IFDIR}isFile(){return(this.mode&sn.S_IFMT)===sn.S_IFREG}isBlockDevice(){return(this.mode&sn.S_IFMT)===sn.S_IFBLK}isCharacterDevice(){return(this.mode&sn.S_IFMT)===sn.S_IFCHR}isSymbolicLink(){return(this.mode&sn.S_IFMT)===sn.S_IFLNK}isFIFO(){return(this.mode&sn.S_IFMT)===sn.S_IFIFO}isSocket(){return(this.mode&sn.S_IFMT)===sn.S_IFSOCK}};function Ar(n){let t=0,e=0;if(typeof n=="object"&&n!==null){if(typeof n.size=="number"){t|=Hn.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|=Hn.UIDGID;let r=n.uid,i=n.gid;Pe[e++]=r>>>24,Pe[e++]=r>>>16,Pe[e++]=r>>>8,Pe[e++]=r,Pe[e++]=i>>>24,Pe[e++]=i>>>16,Pe[e++]=i>>>8,Pe[e++]=i}if(typeof n.mode=="number"||typeof n.mode=="string"){let r=Ua(n.mode);t|=Hn.PERMISSIONS,Pe[e++]=r>>>24,Pe[e++]=r>>>16,Pe[e++]=r>>>8,Pe[e++]=r}if((typeof n.atime=="number"||Ra(n.atime))&&(typeof n.mtime=="number"||Ra(n.mtime))){let r=Wr(n.atime),i=Wr(n.mtime);t|=Hn.ACMODTIME,Pe[e++]=r>>>24,Pe[e++]=r>>>16,Pe[e++]=r>>>8,Pe[e++]=r,Pe[e++]=i>>>24,Pe[e++]=i>>>16,Pe[e++]=i>>>8,Pe[e++]=i}}return{flags:t,nb:e}}function Wr(n){if(typeof n=="number"&&n===n)return n;if(Ra(n))return parseInt(n.getTime()/1e3,10);throw new Error(`Cannot parse time: ${n}`)}function Ua(n){if(typeof n=="number"&&n===n)return n;if(typeof n=="string")return Ua(parseInt(n,8));throw new Error(`Cannot parse mode: ${n}`)}var Oa={r:ke.READ,"r+":ke.READ|ke.WRITE,w:ke.TRUNC|ke.CREAT|ke.WRITE,wx:ke.TRUNC|ke.CREAT|ke.WRITE|ke.EXCL,xw:ke.TRUNC|ke.CREAT|ke.WRITE|ke.EXCL,"w+":ke.TRUNC|ke.CREAT|ke.READ|ke.WRITE,"wx+":ke.TRUNC|ke.CREAT|ke.READ|ke.WRITE|ke.EXCL,"xw+":ke.TRUNC|ke.CREAT|ke.READ|ke.WRITE|ke.EXCL,a:ke.APPEND|ke.CREAT|ke.WRITE,ax:ke.APPEND|ke.CREAT|ke.WRITE|ke.EXCL,xa:ke.APPEND|ke.CREAT|ke.WRITE|ke.EXCL,"a+":ke.APPEND|ke.CREAT|ke.READ|ke.WRITE,"ax+":ke.APPEND|ke.CREAT|ke.READ|ke.WRITE|ke.EXCL,"xa+":ke.APPEND|ke.CREAT|ke.READ|ke.WRITE|ke.EXCL};function ku(n){let t=Oa[n];return t!==void 0?t:null}var vm=(()=>{let n=Object.keys(Oa);return t=>{for(let e=0;e<n.length;++e){let r=n[e];if(Oa[r]===t)return r}return null}})();function qr(n){let t=Q.readUInt32BE();if(t===void 0)return;let e=new Ts;if(t&Hn.SIZE){let r=Q.readUInt64BE(n);if(r===void 0)return;e.size=r}if(t&Hn.UIDGID){let r=Q.readUInt32BE(),i=Q.readUInt32BE();if(i===void 0)return;e.uid=r,e.gid=i}if(t&Hn.PERMISSIONS){let r=Q.readUInt32BE();if(r===void 0)return;e.mode=r}if(t&Hn.ACMODTIME){let r=Q.readUInt32BE(),i=Q.readUInt32BE();if(i===void 0)return;e.atime=r,e.mtime=i}if(t&Hn.EXTENDED){let r=Q.readUInt32BE();if(r===void 0)return;let i={};for(let s=0;s<r;++s){let o=Q.readString(!0),a=Q.readString();if(a===void 0)return;i[o]=a}e.extended=i}return e}function Ze(n,t){let e=vu(n,t);return e!==void 0?(n._buffer.push(e),!1):!0}function vu(n,t){let e=n.outgoing;if(e.state!=="open")return;if(e.window===0)return n._waitWindow=!0,n._chunkcb=_u,t;let r,i=t.length,s=0;for(;i-s>0&&e.window>0;){let o=Math.min(i-s,e.window,e.packetSize);e.window-=o,e.window===0&&(n._waitWindow=!0,n._chunkcb=_u),s===0&&o===i?n._protocol.channelData(n.outgoing.id,t):n._protocol.channelData(n.outgoing.id,Kr(t,s,s+o)),s+=o}return i-s>0&&(s>0?r=Kr(t,s,i):r=t),r}function _u(){this._chunkcb=void 0;let n=this._buffer,t=0;for(;t<n.length;){let e=n[t],r=vu(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 at(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(),Nu(n),!1}function Nu(n){let t=Object.keys(n._requests);if(t.length===0)return;let e=n._requests;n._requests={};let r=new Error("No response from server");for(let i=0;i<t.length;++i){let s=e[t[i]];typeof s.cb=="function"&&s.cb(r)}}function Nm(n,t){let e=9,r=Buffer.allocUnsafe(31);G(r,r.length-4,0),r[4]=Be.EXTENDED;let i=n._writeReqid=n._writeReqid+1&pt;G(r,i,5),G(r,18,e),r.utf8Write("limits@openssh.com",e+=4,18),n._requests[i]={extended:"limits@openssh.com",cb:t};let s=Ze(n,r);if(n._debug){let o=s?"Buffered":"Sending";n._debug(`SFTP: Outbound: ${o} limits@openssh.com`)}}var Bm={[on.VERSION]:(n,t)=>{if(n._version!==-1)return at(n,"Duplicate VERSION packet");let e={};Q.init(t,1);let r=Q.readUInt32BE();for(;Q.avail();){let i=Q.readString(!0),s=Q.readString(!0);if(s===void 0){r=void 0;break}e[i]=s}if(Q.clear(),r===void 0)return at(n,"Malformed VERSION packet");if(n._debug){let i=Object.keys(e);i.length?n._debug(`SFTP: Inbound: Received VERSION (v${r}, exts:${i})`):n._debug(`SFTP: Inbound: Received VERSION (v${r})`)}if(n._version=r,n._extensions=e,e["limits@openssh.com"]==="1")return Nm(n,(i,s)=>{i||(s.maxPktLen>0&&(n._maxOutPktLen=s.maxPktLen),s.maxReadLen>0&&(n._maxReadLen=s.maxReadLen),s.maxWriteLen>0&&(n._maxWriteLen=s.maxWriteLen),n.maxOpenHandles=s.maxOpenHandles>0?s.maxOpenHandles:1/0),n.emit("ready")});n.emit("ready")},[on.STATUS]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readUInt32BE(),i=Q.readString(!0);if(Q.clear(),n._debug){let o=JSON.stringify(i);n._debug(`SFTP: Inbound: Received STATUS (id:${e}, ${r}, ${o})`)}let s=n._requests[e];if(delete n._requests[e],s&&typeof s.cb=="function"){if(r===nt.OK){s.cb();return}let o=new Error(i||Sm[r]||"Unknown status");o.code=r,s.cb(o)}},[on.HANDLE]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString();if(Q.clear(),r===void 0)return e!==void 0&&delete n._requests[e],at(n,"Malformed HANDLE packet");n._debug&&n._debug(`SFTP: Inbound: Received HANDLE (id:${e})`);let i=n._requests[e];delete n._requests[e],i&&typeof i.cb=="function"&&i.cb(void 0,r)},[on.DATA]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r;if(e!==void 0&&(r=n._requests[e],delete n._requests[e]),r&&typeof r.cb=="function")if(r.buffer){let i=Q.readString(r.buffer);if(Q.clear(),i!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${i})`),r.cb(void 0,r.buffer,i);return}}else{let i=Q.readString();if(Q.clear(),i!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${i.length})`),r.cb(void 0,i);return}}else{let i=Q.skipString();if(Q.clear(),i!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received DATA (id:${e}, ${i})`);return}}return at(n,"Malformed DATA packet")},[on.NAME]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let i=Q.readUInt32BE();if(i!==void 0){let s=[];for(let o=0;o<i;++o){let a=Q.readString(!0),c=Q.readString(!0),l=qr(n._biOpt);if(l===void 0){s=void 0;break}s.push({filename:a,longname:c,attrs:l})}if(s!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received NAME (id:${e}, ${s.length})`),Q.clear(),r&&typeof r.cb=="function"&&r.cb(void 0,s);return}}return Q.clear(),at(n,"Malformed NAME packet")},[on.ATTRS]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r;e!==void 0&&(r=n._requests[e],delete n._requests[e]);let i=qr(n._biOpt);if(Q.clear(),i!==void 0){n._debug&&n._debug(`SFTP: Inbound: Received ATTRS (id:${e})`),r&&typeof r.cb=="function"&&r.cb(void 0,i);return}return at(n,"Malformed ATTRS packet")},[on.EXTENDED]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE();if(e!==void 0){let r=n._requests[e];if(r)switch(delete n._requests[e],r.extended){case"statvfs@openssh.com":case"fstatvfs@openssh.com":{let i=n._biOpt,s={f_bsize:Q.readUInt64BE(i),f_frsize:Q.readUInt64BE(i),f_blocks:Q.readUInt64BE(i),f_bfree:Q.readUInt64BE(i),f_bavail:Q.readUInt64BE(i),f_files:Q.readUInt64BE(i),f_ffree:Q.readUInt64BE(i),f_favail:Q.readUInt64BE(i),f_sid:Q.readUInt64BE(i),f_flag:Q.readUInt64BE(i),f_namemax:Q.readUInt64BE(i)};if(s.f_namemax===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),Q.clear(),typeof r.cb=="function"&&r.cb(void 0,s);return}case"limits@openssh.com":{let i={maxPktLen:Q.readUInt64BE(),maxReadLen:Q.readUInt64BE(),maxWriteLen:Q.readUInt64BE(),maxOpenHandles:Q.readUInt64BE()};if(i.maxOpenHandles===void 0)break;n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ${r.extended})`),Q.clear(),typeof r.cb=="function"&&r.cb(void 0,i);return}case"users-groups-by-id@openssh.com":{let i=Q.readUInt32BE();if(i===void 0)break;let s=new Array(i);for(let c=0;c<s.length;++c)s[c]=Q.readString(!0);let o=Q.readUInt32BE();if(o===void 0)break;let a=new Array(o);for(let c=0;c<a.length;++c)a[c]=Q.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})`),Q.clear(),typeof r.cb=="function"&&r.cb(void 0,s,a);return}default:n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),Q.clear(),typeof r.cb=="function"&&r.cb();return}else{n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED_REPLY (id:${e}, ???)`),Q.clear();return}}return Q.clear(),at(n,"Malformed EXTENDED_REPLY packet")}},Rm={[Be.INIT]:(n,t)=>{if(n._version!==-1)return at(n,"Duplicate INIT packet");let e={};Q.init(t,1);let r=Q.readUInt32BE();for(;Q.avail();){let i=Q.readString(!0),s=Q.readString(!0);if(s===void 0){r=void 0;break}e[i]=s}if(Q.clear(),r===void 0)return at(n,"Malformed INIT packet");if(n._debug){let i=Object.keys(e);i.length?n._debug(`SFTP: Inbound: Received INIT (v${r}, exts:${i})`):n._debug(`SFTP: Inbound: Received INIT (v${r})`)}Ze(n,wm),n._version=r,n._extensions=e,n.emit("ready")},[Be.OPEN]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0),i=Q.readUInt32BE(),s=qr(n._biOpt);if(Q.clear(),s===void 0)return at(n,"Malformed OPEN packet");n._debug&&n._debug(`SFTP: Inbound: Received OPEN (id:${e})`),n.emit("OPEN",e,r,i,s)||n.status(e,nt.OP_UNSUPPORTED)},[Be.CLOSE]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString();if(Q.clear(),r===void 0||r.length>256)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(),i=Q.readUInt64BE(n._biOpt),s=Q.readUInt32BE();if(Q.clear(),s===void 0||r.length>256)return at(n,"Malformed READ packet");n._debug&&n._debug(`SFTP: Inbound: Received READ (id:${e})`),n.emit("READ",e,r,i,s)||n.status(e,nt.OP_UNSUPPORTED)},[Be.WRITE]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(),i=Q.readUInt64BE(n._biOpt),s=Q.readString();if(Q.clear(),s===void 0||r.length>256)return at(n,"Malformed WRITE packet");n._debug&&n._debug(`SFTP: Inbound: Received WRITE (id:${e})`),n.emit("WRITE",e,r,i,s)||n.status(e,nt.OP_UNSUPPORTED)},[Be.LSTAT]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(Q.clear(),r===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString();if(Q.clear(),r===void 0||r.length>256)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0),i=qr(n._biOpt);if(Q.clear(),i===void 0)return at(n,"Malformed SETSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received SETSTAT (id:${e})`),n.emit("SETSTAT",e,r,i)||n.status(e,nt.OP_UNSUPPORTED)},[Be.FSETSTAT]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(),i=qr(n._biOpt);if(Q.clear(),i===void 0||r.length>256)return at(n,"Malformed FSETSTAT packet");n._debug&&n._debug(`SFTP: Inbound: Received FSETSTAT (id:${e})`),n.emit("FSETSTAT",e,r,i)||n.status(e,nt.OP_UNSUPPORTED)},[Be.OPENDIR]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(Q.clear(),r===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString();if(Q.clear(),r===void 0||r.length>256)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(Q.clear(),r===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0),i=qr(n._biOpt);if(Q.clear(),i===void 0)return at(n,"Malformed MKDIR packet");n._debug&&n._debug(`SFTP: Inbound: Received MKDIR (id:${e})`),n.emit("MKDIR",e,r,i)||n.status(e,nt.OP_UNSUPPORTED)},[Be.RMDIR]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(Q.clear(),r===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(Q.clear(),r===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(Q.clear(),r===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0),i=Q.readString(!0);if(Q.clear(),i===void 0)return at(n,"Malformed RENAME packet");n._debug&&n._debug(`SFTP: Inbound: Received RENAME (id:${e})`),n.emit("RENAME",e,r,i)||n.status(e,nt.OP_UNSUPPORTED)},[Be.READLINK]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(Q.clear(),r===void 0)return at(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)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0),i=Q.readString(!0);if(Q.clear(),i===void 0)return at(n,"Malformed SYMLINK packet");n._debug&&n._debug(`SFTP: Inbound: Received SYMLINK (id:${e})`);let s;n._isOpenSSH?s=n.emit("SYMLINK",e,i,r):s=n.emit("SYMLINK",e,r,i),s||n.status(e,nt.OP_UNSUPPORTED)},[Be.EXTENDED]:(n,t)=>{Q.init(t,1);let e=Q.readUInt32BE(),r=Q.readString(!0);if(r===void 0)return Q.clear(),at(n,"Malformed EXTENDED packet");let i;Q.avail()&&(i=Q.readRaw()),Q.clear(),n._debug&&n._debug(`SFTP: Inbound: Received EXTENDED (id:${e})`),n.emit("EXTENDED",e,r,i)||n.status(e,nt.OP_UNSUPPORTED)}},{ERR_INVALID_ARG_TYPE:Pm,ERR_OUT_OF_RANGE:Ps,validateNumber:Tm}=Au(),bu=128,Zt,Ma=[];function Om(n){Ma.length>0?Zt=Ma.pop():Zt=Buffer.allocUnsafe(n),Zt.used=0}function La(n,t){if(!Number.isSafeInteger(n))throw Tm(n,t),Number.isInteger(n)?new Ps(t,">= 0 and <= 2 ** 53 - 1",n):new Ps(t,"an integer",n);if(n<0)throw new Ps(t,">= 0 and <= 2 ** 53 - 1",n)}function Ba(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,xu.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&&(La(this.start,"start"),this.pos=this.start),this.end===void 0)this.end=1/0;else if(this.end!==1/0&&(La(this.end,"end"),this.start!==void 0&&this.start>this.end))throw new Ps("start",`<= "end" (here: ${this.end})`,this.start);this.on("end",function(){this.autoClose&&this.destroy()}),Buffer.isBuffer(this.handle)||this.open()}wu(Qn,xu);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<bu)&&Om(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,(i,s)=>{if(i){this.emit("error",i),this.autoClose&&this.destroy();return}let o=null;if(r+e===t.used&&t===Zt)t.used=Ba(t.used+s-e);else{let a=r+e&-8,c=Ba(r+s);a-c>=bu&&Ma.push(t.slice(c,a))}s>0&&(this.bytesRead+=s,o=t.slice(r,r+s)),this.pos+=s,this.push(o)}),Zt.used=Ba(Zt.used+e)};Qn.prototype._destroy=function(n,t){if(this._opening&&!Buffer.isBuffer(this.handle)){this.once("open",Su.bind(null,this,t,n));return}Su(this,t,n),this.handle=null,this._opening=!1};function Su(n,t,e){if(!n.handle)return r();n.sftp.close(n.handle,r);function r(i){i=i||e,t(i),n.isClosed=!0,i||n.emit("close")}}Qn.prototype.close=function(n){this.destroy(null,n)};Object.defineProperty(Qn.prototype,"pending",{get(){return this.handle===null},configurable:!0});function yn(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,Da.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&&(La(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()}wu(yn,Da);yn.prototype._final=function(n){this.autoClose&&this.destroy(),n()};yn.prototype.open=function(){this._opening||(this._opening=!0,this.sftp.open(this.path,this.flags,this.mode,(n,t)=>{if(this._opening=!1,n){this.emit("error",n),this.autoClose&&this.destroy();return}this.handle=t;let e=r=>{if(r){this.sftp.chmod(this.path,this.mode,i=>e());return}if(this.flags[0]==="a"){let i=(s,o)=>{if(s){this.sftp.stat(this.path,(a,c)=>{if(a){this.destroy(),this.emit("error",s);return}i(null,c)});return}this.pos=o.size,this.emit("open",t),this.emit("ready")};this.sftp.fstat(t,i);return}this.emit("open",t),this.emit("ready")};this.sftp.fchmod(t,this.mode,e)}))};yn.prototype._write=function(n,t,e){if(!Buffer.isBuffer(n)){let r=new Pm("data","Buffer",n);return this.emit("error",r)}if(!Buffer.isBuffer(this.handle))return this.once("open",function(){this._write(n,t,e)});this.sftp.write(this.handle,n,0,n.length,this.pos,(r,i)=>{if(r)return this.autoClose&&this.destroy(),e(r);this.bytesWritten+=i,e()}),this.pos+=n.length};yn.prototype._writev=function(n,t){if(!Buffer.isBuffer(this.handle))return this.once("open",function(){this._writev(n,t)});let e=this.sftp,r=this.handle,i=n.length,s=(o,a)=>{if(o)return this.destroy(),t(o);this.bytesWritten+=a,--i===0&&t()};for(let o=0;o<n.length;++o){let a=n[o].chunk;e.write(r,a,0,a.length,this.pos,s),this.pos+=a.length}};typeof Da.prototype.destroy!="function"&&(yn.prototype.destroy=Qn.prototype.destroy);yn.prototype._destroy=Qn.prototype._destroy;yn.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()};yn.prototype.destroySoon=yn.prototype.end;Object.defineProperty(yn.prototype,"pending",{get(){return this.handle===null},configurable:!0});Bu.exports={flagsToString:vm,OPEN_MODE:ke,SFTP:Pa,Stats:Ts,STATUS_CODE:nt,stringToFlags:ku}});var qa=lt((bE,Ou)=>{"use strict";var{Duplex:Mm,Readable:Lm,Writable:Dm}=require("stream"),{CHANNEL_EXTENDED_DATATYPE:{STDERR:Ru}}=Un(),{bufferSlice:Os}=En(),Um=32*1024,Bi=2*1024*1024,Qa=Bi/2,$a=class extends Lm{constructor(t,e){super(e),this._channel=t}_read(t){this._channel._waitChanDrain&&(this._channel._waitChanDrain=!1,this._channel.incoming.window<=Qa&&Wa(this._channel))}},Fa=class extends Dm{constructor(t){super({highWaterMark:Bi}),this._channel=t}_write(t,e,r){let i=this._channel,s=i._client._protocol,o=i.outgoing,a=o.packetSize,c=o.id,l=o.window,u=t.length,f=0;if(o.state==="open"){for(;u-f>0&&l>0;){let h=u-f;h>l&&(h=l),h>a&&(h=a),f===0&&h===u?s.channelExtData(c,t,Ru):s.channelExtData(c,Os(t,f,f+h),Ru),f+=h,l-=h}if(o.window=l,u-f>0){l===0&&(i._waitWindow=!0),f>0?i._chunkErr=Os(t,f,u):i._chunkErr=t,i._chunkcbErr=r;return}r()}}},Ha=class extends Mm{constructor(t,e,r){let i={highWaterMark:Bi,allowHalfOpen:!r||r&&r.allowHalfOpen!==!1,emitClose:!1};super(i),this.allowHalfOpen=i.allowHalfOpen;let s=!!(r&&r.server);this.server=s,this.type=e.type,this.subtype=void 0,this.incoming=e.incoming,this.outgoing=e.outgoing,this._callbacks=[],this._client=t,this._hasX11=!1,this._exit={code:void 0,signal:void 0,dump:void 0,desc:void 0},this.stdin=this.stdout=this,s?this.stderr=new Fa(this):this.stderr=new $a(this,i),this._waitWindow=!1,this._waitChanDrain=!1,this._chunk=void 0,this._chunkcb=void 0,this._chunkErr=void 0,this._chunkcbErr=void 0,this.on("finish",Pu).on("prefinish",Pu),this.on("end",Tu).on("close",Tu)}_read(t){this._waitChanDrain&&(this._waitChanDrain=!1,this.incoming.window<=Qa&&Wa(this))}_write(t,e,r){let i=this._client._protocol,s=this.outgoing,o=s.packetSize,a=s.id,c=s.window,l=t.length,u=0;if(s.state==="open"){for(;l-u>0&&c>0;){let f=l-u;f>c&&(f=c),f>o&&(f=o),u===0&&f===l?i.channelData(a,t):i.channelData(a,Os(t,u,u+f)),u+=f,c-=f}if(s.window=c,l-u>0){c===0&&(this._waitWindow=!0),u>0?this._chunk=Os(t,u,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,i){if(this.server)throw new Error("Client-only method called in server mode");this.type==="session"&&(this.subtype==="shell"||this.subtype==="exec")&&this.writable&&this.outgoing.state==="open"&&this._client._protocol.windowChange(this.outgoing.id,t,e,r,i)}signal(t){if(this.server)throw new Error("Client-only method called in server mode");this.type==="session"&&this.writable&&this.outgoing.state==="open"&&this._client._protocol.signal(this.outgoing.id,t)}exit(t,e,r){if(!this.server)throw new Error("Server-only method called in client mode");this.type==="session"&&this.writable&&this.outgoing.state==="open"&&(typeof t=="number"?this._client._protocol.exitStatus(this.outgoing.id,t):this._client._protocol.exitSignal(this.outgoing.id,t,e,r))}};function Pu(){this.eof(),(this.server||!this.allowHalfOpen)&&this.close(),this.writable=!1}function Tu(){this.readable=!1}function Wa(n){if(n.outgoing.state==="closed")return;let t=Bi-n.incoming.window;t<=0||(n.incoming.window+=t,n._client._protocol.channelWindowAdjust(n.outgoing.id,t))}Ou.exports={Channel:Ha,MAX_WINDOW:Bi,PACKET_SIZE:Um,windowAdjust:Wa,WINDOW_THRESHOLD:Qa}});var za=lt((SE,Du)=>{"use strict";var{SFTP:$m}=Ni(),Ri=2**32-1;function Mu(n,t,e,r){if(n._chanMgr.remove(t),typeof r!="function")return;let i;e instanceof Error?i=e:typeof e=="object"&&e!==null?(i=new Error(`(SSH) Channel open failure: ${e.description}`),i.reason=e.reason):(i=new Error("(SSH) Channel open failure: server closed channel unexpectedly"),i.reason=""),r(i)}function Lu(n,t,e,r,i){if(typeof e=="function"){Mu(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!==$m&&(e.outgoing.state==="open"||e.outgoing.state==="eof")&&!i&&e.close(),e.outgoing.state==="closing"&&(e.outgoing.state="closed");let s=e._readableState,o=e._writableState;o&&!o.ending&&!o.finished&&!i&&e.end();let a=e._callbacks;e._callbacks=[];for(let c=0;c<a.length;++c)a[c](!0);if(e.server)!e.readable||e.destroyed||s&&s.endEmitted?e.emit("close"):e.once("end",()=>e.emit("close"));else{let c;switch(e.type){case"direct-streamlocal@openssh.com":case"direct-tcpip":c=()=>e.emit("close");break;default:{let u=e._exit;c=()=>{u.code===null?e.emit("close",u.code,u.signal,u.dump,u.desc):e.emit("close",u.code)}}}!e.readable||e.destroyed||s&&s.endEmitted?c():e.once("end",c);let 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 Va=class{constructor(t){this._client=t,this._channels={},this._cur=-1,this._count=0}add(t){let e;if(this._cur<Ri)e=++this._cur;else if(this._count===0)this._cur=0,e=0;else{let r=this._channels;for(let i=0;i<Ri;++i)if(r[i]===void 0){e=i;break}}return e===void 0?-1:(this._channels[e]=t||!0,++this._count,e)}update(t,e){if(typeof t!="number"||t<0||t>=Ri||!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>=Ri||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);return this._channels[t]}remove(t){if(typeof t!="number"||t<0||t>=Ri||!isFinite(t))throw new Error(`Invalid channel id: ${t}`);this._channels[t]&&(delete this._channels[t],this._count&&--this._count)}cleanup(t){let e=this._channels;this._channels={},this._cur=-1,this._count=0;let r=Object.keys(e),i=this._client;for(let s=0;s<r.length;++s){let o=+r[s],a=e[o];Lu(i,o,a._channel||a,t,!0)}}},Ka=(()=>{let n=Object.prototype.toString;return t=>n.call(t)==="[object RegExp]"})();function Fm(n,t,e){if(Array.isArray(n)&&n.length>0){for(let r=0;r<n.length;++r)if(e.indexOf(n[r])===-1)throw new Error(`Unsupported algorithm: ${n[r]}`);return n}if(typeof n=="object"&&n!==null){let r=Object.keys(n),i=t;for(let s=0;s<r.length;++s){let o=r[s],a=n[o];switch(o){case"append":if(Array.isArray(a)||(a=[a]),Array.isArray(a))for(let c=0;c<a.length;++c){let l=a[c];if(typeof l=="string"){if(!l||i.indexOf(l)!==-1)continue;if(e.indexOf(l)===-1)throw new Error(`Unsupported algorithm: ${l}`);i===t&&(i=i.slice()),i.push(l)}else if(Ka(l))for(let u=0;u<e.length;++u){let f=e[u];if(l.test(f)){if(i.indexOf(f)!==-1)continue;i===t&&(i=i.slice()),i.push(f)}}}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||i.indexOf(l)!==-1)continue;if(e.indexOf(l)===-1)throw new Error(`Unsupported algorithm: ${l}`);i===t&&(i=i.slice()),i.unshift(l)}else if(Ka(l))for(let u=e.length;u>=0;--u){let f=e[u];if(l.test(f)){if(i.indexOf(f)!==-1)continue;i===t&&(i=i.slice()),i.unshift(f)}}}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 u=i.indexOf(l);if(u===-1)continue;i===t&&(i=i.slice()),i.splice(u,1)}else if(Ka(l))for(let u=0;u<i.length;++u)l.test(i[u])&&(i===t&&(i=i.slice()),i.splice(u,1),--u)}break}}return i}return t}Du.exports={ChannelManager:Va,generateAlgorithmList:Fm,onChannelOpenFailure:Mu,onCHANNEL_CLOSE:Lu,isWritable:n=>n&&n.writable&&n._readableState&&n._readableState.ended===!1}});var ec=lt((xE,rf)=>{"use strict";var{createHash:Hm,getHashes:Qm,randomFillSync:Wm}=require("crypto"),{Socket:qm}=require("net"),{lookup:Km}=require("dns"),Vm=require("events"),zm=Qm(),{COMPAT:ef,CHANNEL_EXTENDED_DATATYPE:{STDERR:Gm},CHANNEL_OPEN_FAILURE:Pi,DEFAULT_CIPHER:Uu,DEFAULT_COMPRESSION:$u,DEFAULT_KEX:Fu,DEFAULT_MAC:Hu,DEFAULT_SERVER_HOST_KEY:Qu,DISCONNECT_REASON:Wu,DISCONNECT_REASON_BY_VALUE:Ym,SUPPORTED_CIPHER:jm,SUPPORTED_COMPRESSION:Xm,SUPPORTED_KEX:Jm,SUPPORTED_MAC:Zm,SUPPORTED_SERVER_HOST_KEY:eg}=Un(),{init:tg}=Gn(),ng=va(),{parseKey:Ds}=Xn(),{SFTP:rg}=Ni(),{bufferCopy:qu,makeBufferParser:tf,makeError:ig,readUInt32BE:sg,sigSSHToASN1:og,writeUInt32BE:Ga}=En(),{AgentContext:Ku,createAgent:Vu,isAgent:zu}=ha(),{Channel:nf,MAX_WINDOW:Us,PACKET_SIZE:$s,windowAdjust:Gu,WINDOW_THRESHOLD:Yu}=qa(),{ChannelManager:ag,generateAlgorithmList:Ti,isWritable:Dt,onChannelOpenFailure:cg,onCHANNEL_CLOSE:lg}=za(),Ms=tf(),Ls=tf(),Oi=/^OpenSSH_(?:(?![0-4])\d)|(?:\d{2,})/,Ja=n=>{},Za=class extends Vm{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&&Dt(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=Ti(t.algorithms.kex,Fu,Jm),e.kex!==Fu&&(r=!1),e.serverHostKey=Ti(t.algorithms.serverHostKey,Qu,eg),e.serverHostKey!==Qu&&(r=!1),e.cs.cipher=Ti(t.algorithms.cipher,Uu,jm),e.cs.cipher!==Uu&&(r=!1),e.cs.mac=Ti(t.algorithms.hmac,Hu,Zm),e.cs.mac!==Hu&&(r=!1),e.cs.compress=Ti(t.algorithms.compress,$u,Xm),e.cs.compress!==$u&&(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=Vu(t.agent):zu(t.agent)?this.config.agent=t.agent:this.config.agent=void 0,this.config.allowAgentFwd=t.agentForward===!0&&this.config.agent!==void 0;let i=this.config.authHandler=typeof t.authHandler=="function"||Array.isArray(t.authHandler)?t.authHandler:void 0;this.config.strictVendor=typeof t.strictVendor=="boolean"?t.strictVendor:!0;let s=this.config.debug=typeof t.debug=="function"?t.debug:void 0;if(t.agentForward===!0&&!this.config.allowAgentFwd)throw new Error("You must set a valid agent path to allow agent forwarding");let o=this._callbacks=[];this._chanMgr=new ag(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=Ds(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 H=t.hostVerifier,B;zm.indexOf(t.hostHash)!==-1&&(B=t.hostHash),c=(L,z)=>{B&&(L=Hm(B).update(L).digest("hex"));let ne=H(L,z);ne!==void 0&&z(ne)}}let l=this._sock=t.sock||new qm,u=!1,f=!1;this._protocol&&this._protocol.cleanup();let h=s?(H,B,L)=>{s(`Debug output from server: ${JSON.stringify(L)}`)}:void 0,p,y=this._protocol=new ng({ident:this.config.ident,offer:r?void 0:e,onWrite:H=>{Dt(l)&&l.write(H)},onError:H=>{H.level==="handshake"&&clearTimeout(this._readyTimeout),y._destruct||l.removeAllListeners("data"),this.emit("error",H);try{l.end()}catch{}},onHeader:H=>{f=!0,this._remoteVer=H.versions.software,H.greeting&&this.emit("greeting",H.greeting)},onHandshakeComplete:H=>{this.emit("handshake",H),u||(u=!0,y.service("ssh-userauth"))},debug:s,hostVerifier:c,messageHandlers:{DEBUG:h,DISCONNECT:(H,B,L)=>{if(B!==Wu.BY_APPLICATION){L||(L=Ym[B],L===void 0&&(L=`Unexpected disconnection reason: ${B}`));let z=new Error(L);z.code=B,this.emit("error",z)}l.end()},SERVICE_ACCEPT:(H,B)=>{B==="ssh-userauth"&&X()},EXT_INFO:(H,B)=>{if(p===void 0){for(let L of B)if(L.name==="server-sig-algs"){p=L.algs;return}p=null}},USERAUTH_BANNER:(H,B)=>{this.emit("banner",B)},USERAUTH_SUCCESS:H=>{C(),clearTimeout(this._readyTimeout),this.emit("ready")},USERAUTH_FAILURE:(H,B,L)=>{if(b.keyAlgos){let z=b.keyAlgos[0][0];if(s&&s(`Client: ${b.type} (${z}) auth failed`),b.keyAlgos.shift(),b.keyAlgos.length){let[ne,de]=b.keyAlgos[0];switch(b.type){case"agent":y.authPK(b.username,b.agentCtx.currentKey(),ne);return;case"publickey":y.authPK(b.username,b.key,ne);return;case"hostbased":y.authHostbased(b.username,b.key,b.localHostname,b.localUsername,ne,(oe,Xe)=>{let dt=b.key.sign(oe,de);if(dt instanceof Error)return dt.message=`Error while signing with key: ${dt.message}`,dt.level="client-authentication",this.emit("error",dt),X();Xe(dt)});return}}else b.keyAlgos=void 0}if(b.type==="agent"){let z=b.agentCtx.pos();return s&&s(`Client: Agent key #${z+1} failed`),re()}s&&s(`Client: ${b.type} auth failed`),w=L,k=B,X()},USERAUTH_PASSWD_CHANGEREQ:(H,B)=>{b.type==="password"&&this.emit("change password",B,L=>{y.authPassword(this.config.username,this.config.password,L)})},USERAUTH_PK_OK:H=>{let B,L;if(b.keyAlgos&&([B,L]=b.keyAlgos[0]),b.type==="agent"){let z=b.agentCtx.currentKey();y.authPK(b.username,z,B,(ne,de)=>{let oe={hash:L};b.agentCtx.sign(z,ne,oe,(Xe,dt)=>{if(Xe)Xe.level="agent",this.emit("error",Xe);else return de(dt);re()})})}else b.type==="publickey"&&y.authPK(b.username,b.key,B,(z,ne)=>{let de=b.key.sign(z,L);if(de instanceof Error)return de.message=`Error signing data with key: ${de.message}`,de.level="client-authentication",this.emit("error",de),X();ne(de)})},USERAUTH_INFO_REQUEST:(H,B,L,z)=>{if(b.type==="keyboard-interactive"){if((Array.isArray(z)?z.length:0)===0){s&&s("Client: Sending automatic USERAUTH_INFO_RESPONSE"),y.authInfoRes();return}b.prompt(B,L,"",z,de=>{y.authInfoRes(de)})}},REQUEST_SUCCESS:(H,B)=>{o.length&&o.shift()(!1,B)},REQUEST_FAILURE:H=>{o.length&&o.shift()(!0)},GLOBAL_REQUEST:(H,B,L,z)=>{B==="hostkeys-00@openssh.com"?(pg(this,z,(ne,de)=>{ne||this.emit("hostkeys",de)}),L&&y.requestSuccess()):L&&y.requestFailure()},CHANNEL_OPEN:(H,B)=>{dg(this,B)},CHANNEL_OPEN_CONFIRMATION:(H,B)=>{let L=this._chanMgr.get(B.recipient);if(typeof L!="function")return;let z=L.type==="sftp",de={type:z?"session":L.type,incoming:{id:B.recipient,window:Us,packetSize:$s,state:"open"},outgoing:{id:B.sender,window:B.window,packetSize:B.packetSize,state:"open"}},oe=z?new rg(this,de,{debug:s}):new nf(this,de);this._chanMgr.update(B.recipient,oe),L(void 0,oe)},CHANNEL_OPEN_FAILURE:(H,B,L,z)=>{let ne=this._chanMgr.get(B);if(typeof ne!="function")return;cg(this,B,{reason:L,description:z},ne)},CHANNEL_DATA:(H,B,L)=>{let z=this._chanMgr.get(B);if(!(typeof z!="object"||z===null)&&z.incoming.window!==0){if(z.incoming.window-=L.length,z.push(L)===!1){z._waitChanDrain=!0;return}z.incoming.window<=Yu&&Gu(z)}},CHANNEL_EXTENDED_DATA:(H,B,L,z)=>{if(z!==Gm)return;let ne=this._chanMgr.get(B);if(!(typeof ne!="object"||ne===null)&&ne.incoming.window!==0){if(ne.incoming.window-=L.length,!ne.stderr.push(L)){ne._waitChanDrain=!0;return}ne.incoming.window<=Yu&&Gu(ne)}},CHANNEL_WINDOW_ADJUST:(H,B,L)=>{let z=this._chanMgr.get(B);typeof z!="object"||z===null||(z.outgoing.window+=L,z._waitWindow&&(z._waitWindow=!1,z._chunk?z._write(z._chunk,null,z._chunkcb):z._chunkcb?z._chunkcb():z._chunkErr?z.stderr._write(z._chunkErr,null,z._chunkcbErr):z._chunkcbErr&&z._chunkcbErr()))},CHANNEL_SUCCESS:(H,B)=>{let L=this._chanMgr.get(B);typeof L!="object"||L===null||(this._resetKA(),L._callbacks.length&&L._callbacks.shift()(!1))},CHANNEL_FAILURE:(H,B)=>{let L=this._chanMgr.get(B);typeof L!="object"||L===null||(this._resetKA(),L._callbacks.length&&L._callbacks.shift()(!0))},CHANNEL_REQUEST:(H,B,L,z,ne)=>{let de=this._chanMgr.get(B);if(typeof de!="object"||de===null)return;let oe=de._exit;if(oe.code===void 0){switch(L){case"exit-status":de.emit("exit",oe.code=ne);return;case"exit-signal":de.emit("exit",oe.code=null,oe.signal=`SIG${ne.signal}`,oe.dump=ne.coreDumped,oe.desc=ne.errorMessage);return}z&&H.channelFailure(de.outgoing.id)}},CHANNEL_EOF:(H,B)=>{let L=this._chanMgr.get(B);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:(H,B)=>{lg(this,B,this._chanMgr.get(B))}}});l.pause();let E=this.config.keepaliveInterval,S=this.config.keepaliveCountMax,x=0,P,q=()=>{if(++x>S){if(clearInterval(P),l.readable){let H=new Error("Keepalive timeout");H.level="client-timeout",this.emit("error",H),l.destroy()}return}Dt(l)?(o.push(C),y.ping()):clearInterval(P)};function C(){E>0&&(x=0,clearInterval(P),Dt(l)&&(P=setInterval(q,E)))}this._resetKA=C;let $=(()=>{let H=!1;return()=>{if(!H&&(H=!0,v&&!f)){let B=ig("Connection lost before handshake","protocol",!0);this.emit("error",B)}}})(),F=(()=>{let H=!1;return()=>{H||(H=!0,v=!0,s&&s("Socket connected"),this.emit("connect"),tg.then(()=>{y.start(),l.on("data",B=>{try{y.parse(B,0,B.length)}catch(L){this.emit("error",L);try{Dt(l)&&l.end()}catch{}}}),l.stderr&&typeof l.stderr.resume=="function"&&l.stderr.resume(),l.resume()}).catch(B=>{this.emit("error",B);try{Dt(l)&&l.end()}catch{}}))}})(),v=!1;l.on("connect",F).on("timeout",()=>{this.emit("timeout")}).on("error",H=>{s&&s(`Socket error: ${H.message}`),clearTimeout(this._readyTimeout),H.level="client-socket",this.emit("error",H)}).on("end",()=>{s&&s("Socket ended"),$(),y.cleanup(),clearTimeout(this._readyTimeout),clearInterval(P),this.emit("end")}).on("close",()=>{s&&s("Socket closed"),$(),y.cleanup(),clearTimeout(this._readyTimeout),clearInterval(P),this.emit("close");let H=o;o=this._callbacks=[];let B=new Error("No response from server");for(let L=0;L<H.length;++L)H[L](B);this._chanMgr.cleanup(B)});let b,w=null,k=null,N=["none"];this.config.password!==void 0&&N.push("password"),a!==void 0&&N.push("publickey"),this._agent!==void 0&&N.push("agent"),this.config.tryKeyboard&&N.push("keyboard-interactive"),a!==void 0&&this.config.localHostname!==void 0&&this.config.localUsername!==void 0&&N.push("hostbased"),Array.isArray(i)?i=Zu(i):typeof i!="function"&&(i=Zu(N));let R=!1,ie=H=>{if(!R){if(R=!0,H===!1){let B=new Error("All configured authentication methods failed");B.level="client-authentication",this.emit("error",B),this.end();return}if(typeof H=="string"){let B=H;if(N.indexOf(B)===-1)return j(`Authentication method not allowed: ${B}`);let L=this.config.username;switch(B){case"password":H={type:B,username:L,password:this.config.password};break;case"publickey":H={type:B,username:L,key:a};break;case"hostbased":H={type:B,username:L,key:a,localHostname:this.config.localHostname,localUsername:this.config.localUsername};break;case"agent":H={type:B,username:L,agentCtx:new Ku(this._agent)};break;case"keyboard-interactive":H={type:B,username:L,prompt:(...z)=>this.emit("keyboard-interactive",...z)};break;case"none":H={type:B,username:L};break;default:return j(`Skipping unsupported authentication method: ${H}`)}}else{if(typeof H!="object"||H===null)return j(`Skipping invalid authentication attempt: ${H}`);{let B=H.username;if(typeof B!="string")return j(`Skipping invalid authentication attempt: ${H}`);let L=H.type;switch(L){case"password":{let{password:z}=H;if(typeof z!="string"&&!Buffer.isBuffer(z))return j("Skipping invalid password auth attempt");H={type:L,username:B,password:z};break}case"publickey":{let z=Ds(H.key,H.passphrase);if(z instanceof Error)return j("Skipping invalid key auth attempt");if(!z.isPrivateKey())return j("Skipping non-private key");H={type:L,username:B,key:z};break}case"hostbased":{let{localHostname:z,localUsername:ne}=H,de=Ds(H.key,H.passphrase);if(de instanceof Error||typeof z!="string"||typeof ne!="string")return j("Skipping invalid hostbased auth attempt");if(!de.isPrivateKey())return j("Skipping non-private key");H={type:L,username:B,key:de,localHostname:z,localUsername:ne};break}case"agent":{let z=H.agent;if(typeof z=="string"&&z.length)z=Vu(z);else if(!zu(z))return j(`Skipping invalid agent: ${H.agent}`);H={type:L,username:B,agentCtx:new Ku(z)};break}case"keyboard-interactive":{let{prompt:z}=H;if(typeof z!="function")return j("Skipping invalid keyboard-interactive auth attempt");H={type:L,username:B,prompt:z};break}case"none":H={type:L,username:B};break;default:return j(`Skipping unsupported authentication method: ${H}`)}}}b=H;try{let B=b.username;switch(b.type){case"password":y.authPassword(B,b.password);break;case"publickey":{let L;if(b.keyAlgos=Xa(this,b.key,p),b.keyAlgos)if(b.keyAlgos.length)L=b.keyAlgos[0][0];else return j("Skipping key authentication (no mutual hash algorithm)");y.authPK(B,b.key,L);break}case"hostbased":{let L,z;if(b.keyAlgos=Xa(this,b.key,p),b.keyAlgos)if(b.keyAlgos.length)[L,z]=b.keyAlgos[0];else return j("Skipping hostbased authentication (no mutual hash algorithm)");y.authHostbased(B,b.key,b.localHostname,b.localUsername,L,(ne,de)=>{let oe=b.key.sign(ne,z);if(oe instanceof Error)return oe.message=`Error while signing with key: ${oe.message}`,oe.level="client-authentication",this.emit("error",oe),X();de(oe)});break}case"agent":b.agentCtx.init(L=>{if(L)return L.level="agent",this.emit("error",L),X();re()});break;case"keyboard-interactive":y.authKeyboard(B);break;case"none":y.authNone(B);break}}finally{R=!1}}};function j(H){s&&s(H),process.nextTick(X)}function X(){R=!1;let H=i(k,w,ie);R||H===void 0||ie(H)}let re=()=>{if(b.type==="agent"){let H=b.agentCtx.nextKey();if(H===!1)s&&s("Agent: No more keys left to try"),s&&s("Client: agent auth failed"),X();else{let B=b.agentCtx.pos(),L;if(b.keyAlgos=Xa(this,H,p),b.keyAlgos)if(b.keyAlgos.length)L=b.keyAlgos[0][0];else{s&&s(`Agent: Skipping key #${B+1} (no mutual hash algorithm)`),re();return}s&&s(`Agent: Trying key #${B+1}`),y.authPK(b.username,H,L)}}},fe=()=>{this.config.readyTimeout>0&&(this._readyTimeout=setTimeout(()=>{let H=new Error("Timed out while waiting for handshake");H.level="client-timeout",this.emit("error",H),l.destroy()},this.config.readyTimeout))};if(t.sock)fe(),typeof l.connecting=="boolean"&&l.connecting||F();else{let H=this.config.host,B=this.config.forceIPv4,L=this.config.forceIPv6;s&&s(`Client: Trying ${H} on port ${this.config.port} ...`);let z=()=>{fe(),l.connect({host:H,port:this.config.port,localAddress:this.config.localAddress,localPort:this.config.localPort}),l.setMaxListeners(0),l.setTimeout(typeof t.timeout=="number"?t.timeout:0)};!B&&!L||B&&L?z():Km(H,B?4:6,(ne,de,oe)=>{if(ne){let Xe=B?"IPv4":"IPv6",dt=new Error(`Error while looking up ${Xe} address for '${H}': ${ne}`);clearTimeout(this._readyTimeout),dt.level="client-dns",this.emit("error",dt),this.emit("close");return}H=de,z()})}return this}end(){return this._sock&&Dt(this._sock)&&(this._protocol.disconnect(Wu.BY_APPLICATION),this._sock.end()),this}destroy(){return this._sock&&Dt(this._sock)&&this._sock.destroy(),this}exec(t,e,r){if(!this._sock||!Dt(this._sock))throw new Error("Not connected");typeof e=="function"&&(r=e,e={});let i={allowHalfOpen:e.allowHalfOpen!==!1};return Vr(this,"session",i,(s,o)=>{if(s){r(s);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(()=>Ju(o,c)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&Ya(o,e.env),(typeof e.pty=="object"&&e.pty!==null||e.pty===!0)&&a.push(()=>Xu(o,e.pty,c)),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&a.push(()=>ju(o,e.x11,c))),a.push(()=>fg(o,t,e,r)),a.shift()()}),this}shell(t,e,r){if(!this._sock||!Dt(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),Vr(this,"session",(i,s)=>{if(i){r(i);return}let o=[];function a(c){if(c){s.close(),r(c);return}o.length&&o.shift()()}(this.config.allowAgentFwd===!0||e&&e.agentForward===!0&&this._agent!==void 0)&&o.push(()=>Ju(s,a)),t!==!1&&o.push(()=>Xu(s,t,a)),typeof e=="object"&&e!==null&&(typeof e.env=="object"&&e.env!==null&&Ya(s,e.env),(typeof e.x11=="object"&&e.x11!==null||e.x11==="number"||e.x11===!0)&&o.push(()=>ju(s,e.x11,a))),o.push(()=>ug(s,r)),o.shift()()}),this}subsys(t,e){if(!this._sock||!Dt(this._sock))throw new Error("Not connected");return Vr(this,"session",(r,i)=>{if(r){e(r);return}ja(i,t,(s,o)=>{if(s){e(s);return}e(void 0,o)})}),this}forwardIn(t,e,r){if(!this._sock||!Dt(this._sock))throw new Error("Not connected");let i=typeof r=="function";return i&&this._callbacks.push((s,o)=>{if(s){r(s!==!0?s:new Error(`Unable to bind to ${t}:${e}`));return}let a=e;e===0&&o&&o.length>=4&&(a=sg(o,0),this._protocol._compatFlags&ef.DYN_RPORT_BUG||(e=a)),this._forwarding[`${t}:${e}`]=a,r(void 0,a)}),this._protocol.tcpipForward(t,e,i),this}unforwardIn(t,e,r){if(!this._sock||!Dt(this._sock))throw new Error("Not connected");let i=typeof r=="function";return i&&this._callbacks.push(s=>{if(s){r(s!==!0?s:new Error(`Unable to unbind from ${t}:${e}`));return}delete this._forwarding[`${t}:${e}`],r()}),this._protocol.cancelTcpipForward(t,e,i),this}forwardOut(t,e,r,i,s){if(!this._sock||!Dt(this._sock))throw new Error("Not connected");let o={srcIP:t,srcPort:e,dstIP:r,dstPort:i};return typeof s!="function"&&(s=Ja),Vr(this,"direct-tcpip",o,s),this}openssh_noMoreSessions(t){if(!this._sock||!Dt(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||!Dt(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(i=>{if(i){e(i!==!0?i:new Error(`Unable to bind to ${t}`));return}this._forwardingUnix[t]=!0,e()}),this._protocol.openssh_streamLocalForward(t,r),this):r?(process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this):this}openssh_unforwardInStreamLocal(t,e){if(!this._sock||!Dt(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(i=>{if(i){e(i!==!0?i:new Error(`Unable to unbind from ${t}`));return}delete this._forwardingUnix[t],e()}),this._protocol.openssh_cancelStreamLocalForward(t,r),this):r?(process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version")),this):this}openssh_forwardOutStreamLocal(t,e){if(!this._sock||!Dt(this._sock))throw new Error("Not connected");return typeof e!="function"&&(e=Ja),!this.config.strictVendor||this.config.strictVendor&&Oi.test(this._remoteVer)?(Vr(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||!Dt(this._sock))throw new Error("Not connected");return typeof t=="function"&&(e=t,t=void 0),Vr(this,"sftp",(r,i)=>{if(r){e(r);return}let s=(o,a)=>{if(o){e(o);return}function c(){i.removeListener("ready",l),i.removeListener("error",u),i.removeListener("exit",f),i.removeListener("close",f)}function l(){c(),e(void 0,i)}function u(h){c(),e(h)}function f(h,p){c();let y;typeof h=="number"?y=`Received exit code ${h} while establishing SFTP session`:p!==void 0?y=`Received signal ${p} while establishing SFTP session`:y="Received unexpected SFTP session termination";let E=new Error(y);E.code=h,E.signal=p,e(E)}i.on("ready",l).on("error",u).on("exit",f).on("close",f),i._init()};typeof t=="object"&&t!==null?Ya(i,t,o=>{if(o){e(o);return}ja(i,"sftp",s)}):ja(i,"sftp",s)}),this}setNoDelay(t){return this._sock&&typeof this._sock.setNoDelay=="function"&&this._sock.setNoDelay(t),this}};function Vr(n,t,e,r){let i=Us,s=$s;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,i,s);break;case"direct-tcpip":n._protocol.directTcpip(a,i,s,e);break;case"direct-streamlocal@openssh.com":n._protocol.openssh_directStreamLocal(a,i,s,e);break;default:throw new Error(`Unsupported channel type: ${t}`)}}function ju(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=hg());let i=typeof e=="function";if(n.outgoing.state!=="open"){i&&e(new Error("Channel is not open"));return}i&&n._callbacks.push(s=>{if(s){e(s!==!0?s:new Error("Unable to request X11"));return}n._hasX11=!0,++n._client._acceptX11,n.once("close",()=>{n._client._acceptX11&&--n._client._acceptX11}),e()}),n._client._protocol.x11Forward(n.outgoing.id,r,i)}function Xu(n,t,e){let r=24,i=80,s=640,o=480,a="vt100",c=null;typeof t=="function"?e=t:typeof t=="object"&&t!==null&&(typeof t.rows=="number"&&(r=t.rows),typeof t.cols=="number"&&(i=t.cols),typeof t.width=="number"&&(s=t.width),typeof t.height=="number"&&(o=t.height),typeof t.term=="string"&&(a=t.term),typeof t.modes=="object"&&(c=t.modes));let l=typeof e=="function";if(n.outgoing.state!=="open"){l&&e(new Error("Channel is not open"));return}l&&n._callbacks.push(u=>{if(u){e(u!==!0?u:new Error("Unable to request a pseudo-terminal"));return}e()}),n._client._protocol.pty(n.outgoing.id,r,i,o,s,a,c,l)}function Ju(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 ug(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 fg(n,t,e,r){if(n.outgoing.state!=="open"){r(new Error("Channel is not open"));return}n._callbacks.push(i=>{if(i){r(i!==!0?i:new Error("Unable to exec"));return}n.subtype="exec",n.allowHalfOpen=e.allowHalfOpen!==!1,r(void 0,n)}),n._client._protocol.exec(n.outgoing.id,t,!0)}function Ya(n,t,e){let r=typeof e=="function";if(n.outgoing.state!=="open"){r&&e(new Error("Channel is not open"));return}r&&n._callbacks.push(s=>{if(s){e(s!==!0?s:new Error("Unable to set environment"));return}e()});let i=Object.keys(t||{});for(let s=0;s<i.length;++s){let o=i[s],a=t[o];n._client._protocol.env(n.outgoing.id,o,a,r)}}function ja(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 dg(n,t){let e=-1,r,i=()=>{let c={type:t.type,incoming:{id:e,window:Us,packetSize:$s,state:"open"},outgoing:{id:t.sender,window:t.window,packetSize:t.packetSize,state:"open"}},l=new nf(n,c);return n._chanMgr.update(e,l),n._protocol.channelOpenConfirm(t.sender,e,Us,$s),l},s=()=>{r===void 0&&(e===-1?r=Pi.RESOURCE_SHORTAGE:r=Pi.CONNECT_FAILED),e!==-1&&n._chanMgr.remove(e),n._protocol.channelOpenFail(t.sender,r,"")},o=()=>(e=n._chanMgr.add(),e===-1&&(r=Pi.RESOURCE_SHORTAGE,n.config.debug&&n.config.debug("Client: Automatic rejection of incoming channel open: no channels available")),e!==-1),a=t.data;switch(t.type){case"forwarded-tcpip":{let c=n._forwarding[`${a.destIP}:${a.destPort}`];if(c!==void 0&&o()){a.destPort===0&&(a.destPort=c),n.emit("tcp connection",a,i,s);return}break}case"forwarded-streamlocal@openssh.com":if(n._forwardingUnix[a.socketPath]!==void 0&&o()){n.emit("unix connection",a,i,s);return}break;case"auth-agent@openssh.com":if(n._agentFwdEnabled&&typeof n._agent.getStream=="function"&&o()){n._agent.getStream((c,l)=>{if(c)return s();let u=i();u.pipe(l).pipe(u)});return}break;case"x11":if(n._acceptX11!==0&&o()){n.emit("x11",a,i,s);return}break;default:r=Pi.UNKNOWN_CHANNEL_TYPE,n.config.debug&&n.config.debug(`Client: Automatic rejection of unsupported incoming channel open type: ${t.type}`)}r===void 0&&(r=Pi.ADMINISTRATIVELY_PROHIBITED,n.config.debug&&n.config.debug("Client: Automatic rejection of unexpected incoming channel open for: "+t.type)),s()}var hg=(()=>{let n=Buffer.allocUnsafe(16);return()=>(Wm(n,0,16),n.hexSlice(0,16))})();function Zu(n){if(!Array.isArray(n))throw new Error("authList must be an array");let t=0;return(e,r,i)=>t===n.length?!1:n[t++]}function pg(n,t,e){if(!n._sock||!Dt(n._sock))return;if(typeof e!="function"&&(e=Ja),!Array.isArray(t))throw new TypeError("Invalid keys argument type");let r=[];for(let i of t){let s=Ds(i);if(s instanceof Error)throw s;r.push(s)}if(!n.config.strictVendor||n.config.strictVendor&&Oi.test(n._remoteVer)){n._callbacks.push((i,s)=>{if(i){e(i!==!0?i:new Error("Server failed to prove supplied keys"));return}let o=[],a=0;for(Ms.init(s,0);Ms.avail()&&a!==r.length;){let c=r[a++],l=c.getPublicSSH(),u=Ms.readString();Ls.init(u,0);let f=Ls.readString(!0),h=Ls.readString(),p;if(f!==c.type)if(c.type==="ssh-rsa")switch(f){case"rsa-sha2-256":p="sha256";break;case"rsa-sha2-512":p="sha512";break;default:continue}else continue;let y=n._protocol._kex.sessionID,E=Buffer.allocUnsafe(37+y.length+4+l.length),S=0;Ga(E,29,S),E.utf8Write("hostkeys-prove-00@openssh.com",S+=4,29),Ga(E,y.length,S+=29),qu(y,E,0,y.length,S+=4),Ga(E,l.length,S+=y.length),qu(l,E,0,l.length,S+=4),(h=og(h,f))&&c.verify(E,h,p)===!0&&o.push(c)}Ls.clear(),Ms.clear(),e(null,o)}),n._protocol.openssh_hostKeysProve(r);return}process.nextTick(e,new Error("strictVendor enabled and server is not OpenSSH or compatible version"))}function Xa(n,t,e){switch(t.type){case"ssh-rsa":if(n._protocol._compatFlags&ef.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"]]}}rf.exports=Za});var of=lt(sf=>{"use strict";var{Agent:nc}=require("http"),{Agent:mg}=require("https"),{connect:gg}=require("tls"),tc;for(let n of[nc,mg]){class t extends n{constructor(r,i){super(i),this._connectCfg=r,this._defaultSrcIP=i&&i.srcIP||"localhost"}createConnection(r,i){let s=r&&r.localAddress||this._defaultSrcIP,o=r&&r.localPort||0,a=r.host,c=r.port;tc===void 0&&(tc=ec());let l=new tc,u=!1;l.on("ready",()=>{l.forwardOut(s,o,a,c,(f,h)=>{if(u=!0,f)return l.end(),i(f);h.once("close",()=>l.end()),i(null,Ag(h,n,r))})}).on("error",i).on("close",()=>{u||i(new Error("Unexpected connection close"))}).connect(this._connectCfg)}}sf[n===nc?"SSHTTPAgent":"SSHTTPSAgent"]=t}function Mi(){}function Ag(n,t,e){if(t===nc)return n.setKeepAlive=Mi,n.setNoDelay=Mi,n.setTimeout=Mi,n.ref=Mi,n.unref=Mi,n.destroySoon=n.destroy,n;e.socket=n;let r=gg(e),i=(()=>{let s=!1;return()=>{s||(s=!0,n.isPaused()&&n.resume())}})();return r.on("end",i).on("close",i),r}});var cf=lt((IE,oc)=>{"use strict";var{Server:yg}=require("net"),Di=require("events"),{listenerCount:Xt}=Di,{CHANNEL_OPEN_FAILURE:zr,DEFAULT_CIPHER:Eg,DEFAULT_COMPRESSION:_g,DEFAULT_KEX:bg,DEFAULT_MAC:Sg,DEFAULT_SERVER_HOST_KEY:xg,DISCONNECT_REASON:Gr,DISCONNECT_REASON_BY_VALUE:wg,SUPPORTED_CIPHER:Ig,SUPPORTED_COMPRESSION:Cg,SUPPORTED_KEX:kg,SUPPORTED_MAC:vg,SUPPORTED_SERVER_HOST_KEY:Ng}=Un(),{init:Bg}=Gn(),{KexInit:Rg}=Ss(),{parseKey:af}=Xn(),Pg=va(),{SFTP:Tg}=Ni(),{writeUInt32BE:Og}=En(),{Channel:Yr,MAX_WINDOW:er,PACKET_SIZE:tr,windowAdjust:Mg,WINDOW_THRESHOLD:Lg}=qa(),{ChannelManager:Dg,generateAlgorithmList:Li,isWritable:Fs,onChannelOpenFailure:Ug,onCHANNEL_CLOSE:$g}=za(),Fg=10,nr=class extends Di{constructor(t,e,r,i,s){super(),this.username=this.user=e,this.service=r,this.method=i,this._initialResponse=!1,this._finalResponse=!1,this._multistep=!1,this._cbfinal=(o,a,c)=>{this._finalResponse||(this._finalResponse=!0,s(this,o,a,c))},this._protocol=t}accept(){this._cleanup&&this._cleanup(),this._initialResponse=!0,this._cbfinal(!0)}reject(t,e){this._cleanup&&this._cleanup(),this._initialResponse=!0,this._cbfinal(!1,t,e)}},Hs=class extends nr{constructor(t,e,r,i,s,o){super(t,e,r,i,o),this._multistep=!0,this._cb=void 0,this._onInfoResponse=a=>{let c=this._cb;c&&(this._cb=void 0,c(a))},this.submethods=s,this.on("abort",()=>{this._cb&&this._cb(new Error("Authentication request aborted"))})}prompt(t,e,r,i){Array.isArray(t)||(t=[t]),typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"?(i=r,r=void 0):typeof i!="function"&&(i=void 0);for(let s=0;s<t.length;++s)typeof t[s]=="string"&&(t[s]={prompt:t[s],echo:!0});this._cb=i,this._initialResponse=!0,this._protocol.authInfoReq(e,r,t)}},ic=class extends nr{constructor(t,e,r,i,s,o){super(t,e,r,i,o),this.key={algo:s.keyAlgo,data:s.key},this.hashAlgo=s.hashAlgo,this.signature=s.signature,this.blob=s.blob}accept(){this.signature?nr.prototype.accept.call(this):(this._initialResponse=!0,this._protocol.authPKOK(this.key.algo,this.key.data))}},sc=class extends nr{constructor(t,e,r,i,s,o){super(t,e,r,i,o),this.key={algo:s.keyAlgo,data:s.key},this.hashAlgo=s.hashAlgo,this.signature=s.signature,this.blob=s.blob,this.localHostname=s.localHostname,this.localUsername=s.localUsername}},Qs=class extends nr{constructor(t,e,r,i,s,o){super(t,e,r,i,o),this.password=s,this._changeCb=void 0}requestChange(t,e){if(this._changeCb)throw new Error("Change request already in progress");if(typeof t!="string")throw new Error("prompt argument must be a string");if(typeof e!="function")throw new Error("Callback argument must be a function");this._changeCb=e,this._protocol.authPasswdChg(t)}},Nn=class extends Di{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:er,packetSize:tr,state:"open"},outgoing:{id:e.sender,window:e.window,packetSize:e.packetSize,state:"open"}}}},dn=class extends Di{constructor(t,e){if(super(),typeof t!="object"||t===null)throw new Error("Missing configuration object");let r=Object.create(null),i=[],s=t.hostKeys;if(!Array.isArray(s))throw new Error("hostKeys must be an array");let o=typeof t.algorithms=="object"&&t.algorithms!==null?t.algorithms:{},a=Li(o.serverHostKey,xg,Ng);for(let h=0;h<s.length;++h){let p;if(Buffer.isBuffer(s[h])||typeof s[h]=="string"?p=af(s[h]):p=af(s[h].key,s[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(!i.includes(p.type))if(p.type==="ssh-rsa"){let y=a.indexOf("ssh-rsa"),E=a.indexOf("rsa-sha2-256"),S=a.indexOf("rsa-sha2-512");y===-1&&(y=1/0),[y,E,S].sort(Hg).forEach(x=>{if(x===-1)return;let P;switch(x){case y:P="ssh-rsa";break;case E:P="rsa-sha2-256";break;case S:P="rsa-sha2-512";break;default:return}r[P]=p,i.push(P)})}else r[p.type]=p,i.push(p.type)}let c={kex:Li(o.kex,bg,kg).concat(["kex-strict-s-v00@openssh.com"]),serverHostKey:i,cs:{cipher:Li(o.cipher,Eg,Ig),mac:Li(o.hmac,Sg,vg),compress:Li(o.compress,_g,Cg),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,u=t.ident?Buffer.from(t.ident):void 0,f=new Rg(c);this._srv=new yg(h=>{if(this._connections>=this.maxConnections){h.destroy();return}++this._connections,h.once("close",()=>{--this._connections});let p;if(l){let y=`[${process.hrtime().join(".")}] `;p=E=>{l(`${y}${E}`)}}new Ws(h,r,u,f,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}};dn.KEEPALIVE_CLIENT_INTERVAL=15e3;dn.KEEPALIVE_CLIENT_COUNT_MAX=3;var Ws=class extends Di{constructor(t,e,r,i,s,o,a){super();let c=0,l=!1,u=[],f,h,p,y=[];this._sock=t,this._chanMgr=new Dg(this),this._debug=s,this.noMoreSessions=!1,this.authenticated=!1;function E(v){}this.on("error",E);let S=s?(v,b,w)=>{s(`Debug output from client: ${JSON.stringify(w)}`)}:void 0,x=typeof a.keepaliveInterval=="number"&&isFinite(a.keepaliveInterval)&&a.keepaliveInterval>0?a.keepaliveInterval:typeof dn.KEEPALIVE_CLIENT_INTERVAL=="number"&&isFinite(dn.KEEPALIVE_CLIENT_INTERVAL)&&dn.KEEPALIVE_CLIENT_INTERVAL>0?dn.KEEPALIVE_CLIENT_INTERVAL:-1,P=typeof a.keepaliveCountMax=="number"&&isFinite(a.keepaliveCountMax)&&a.keepaliveCountMax>=0?a.keepaliveCountMax:typeof dn.KEEPALIVE_CLIENT_COUNT_MAX=="number"&&isFinite(dn.KEEPALIVE_CLIENT_COUNT_MAX)&&dn.KEEPALIVE_CLIENT_COUNT_MAX>=0?dn.KEEPALIVE_CLIENT_COUNT_MAX:-1,q=0;x!==-1&&P!==-1&&(this.once("ready",()=>{let v=()=>{clearInterval(h)};this.on("close",v).on("end",v),h=setInterval(()=>{if(++q>P){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(),q=0});let C=this._protocol=new Pg({server:!0,hostKeys:e,ident:r,offer:i,onPacket:p,greeting:a.greeting,banner:a.banner,onWrite:v=>{Fs(t)&&t.write(v)},onError:v=>{C._destruct||t.removeAllListeners("data"),this.emit("error",v);try{t.end()}catch{}},onHeader:v=>{this.removeListener("error",E);let b={ip:t.remoteAddress,family:t.remoteFamily,port:t.remotePort,header:v};if(!o.emit("connection",this,b)){C.disconnect(Gr.BY_APPLICATION),t.end();return}v.greeting&&this.emit("greeting",v.greeting)},onHandshakeComplete:v=>{++c>1&&this.emit("rekey"),this.emit("handshake",v)},debug:s,messageHandlers:{DEBUG:S,DISCONNECT:(v,b,w)=>{if(b!==Gr.BY_APPLICATION){w||(w=wg[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:(v,b)=>{if(b.type==="session"&&this.noMoreSessions||!this.authenticated){let re=zr.ADMINISTRATIVELY_PROHIBITED;return C.channelOpenFail(b.sender,re)}let w=-1,k,N=!1,R,ie=()=>{N||(N=!0,k===void 0&&(w===-1?k=zr.RESOURCE_SHORTAGE:k=zr.CONNECT_FAILED),w!==-1&&this._chanMgr.remove(w),C.channelOpenFail(b.sender,k,""))},j=()=>(w=this._chanMgr.add(),w===-1&&(k=zr.RESOURCE_SHORTAGE,s&&s("Automatic rejection of incoming channel open: no channels available")),w!==-1),X=b.data;switch(b.type){case"session":if(Xt(this,"session")&&j()){R=()=>{if(N)return;N=!0;let re=new Nn(this,b,w);return this._chanMgr.update(w,re),C.channelOpenConfirm(b.sender,w,er,tr),re},this.emit("session",R,ie);return}break;case"direct-tcpip":if(Xt(this,"tcpip")&&j()){R=()=>{if(N)return;N=!0;let re={type:void 0,incoming:{id:w,window:er,packetSize:tr,state:"open"},outgoing:{id:b.sender,window:b.window,packetSize:b.packetSize,state:"open"}},fe=new Yr(this,re,{server:!0});return this._chanMgr.update(w,fe),C.channelOpenConfirm(b.sender,w,er,tr),fe},this.emit("tcpip",R,ie,X);return}break;case"direct-streamlocal@openssh.com":if(Xt(this,"openssh.streamlocal")&&j()){R=()=>{if(N)return;N=!0;let re={type:void 0,incoming:{id:w,window:er,packetSize:tr,state:"open"},outgoing:{id:b.sender,window:b.window,packetSize:b.packetSize,state:"open"}},fe=new Yr(this,re,{server:!0});return this._chanMgr.update(w,fe),C.channelOpenConfirm(b.sender,w,er,tr),fe},this.emit("openssh.streamlocal",R,ie,X);return}break;default:k=zr.UNKNOWN_CHANNEL_TYPE,s&&s(`Automatic rejection of unsupported incoming channel open type: ${b.type}`)}k===void 0&&(k=zr.ADMINISTRATIVELY_PROHIBITED,s&&s(`Automatic rejection of unexpected incoming channel open for: ${b.type}`)),ie()},CHANNEL_OPEN_CONFIRMATION:(v,b)=>{let w=this._chanMgr.get(b.recipient);if(typeof w!="function")return;let k={type:w.type,incoming:{id:b.recipient,window:er,packetSize:tr,state:"open"},outgoing:{id:b.sender,window:b.window,packetSize:b.packetSize,state:"open"}},N=new Yr(this,k,{server:!0});this._chanMgr.update(b.recipient,N),w(void 0,N)},CHANNEL_OPEN_FAILURE:(v,b,w,k)=>{let N=this._chanMgr.get(b);if(typeof N!="function")return;Ug(this,b,{reason:w,description:k},N)},CHANNEL_DATA:(v,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<=Lg&&Mg(k)}},CHANNEL_EXTENDED_DATA:(v,b,w,k)=>{},CHANNEL_WINDOW_ADJUST:(v,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:(v,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:(v,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:(v,b,w,k,N)=>{let R=this._chanMgr.get(b);if(typeof R!="object"||R===null)return;let ie=!1,j,X;if(R.constructor!==Nn){k&&C.channelFailure(R.outgoing.id);return}if(k&&(w!=="shell"&&w!=="exec"&&w!=="subsystem"&&(j=()=>{ie||R._ending||R._channel||(ie=!0,C.channelSuccess(R._chanInfo.outgoing.id))}),X=()=>{ie||R._ending||R._channel||(ie=!0,C.channelFailure(R._chanInfo.outgoing.id))}),R._ending){X&&X();return}switch(w){case"env":if(Xt(R,"env")){R.emit("env",j,X,{key:N.name,val:N.value});return}break;case"pty-req":if(Xt(R,"pty")){R.emit("pty",j,X,N);return}break;case"window-change":Xt(R,"window-change")?R.emit("window-change",j,X,N):X&&X();break;case"x11-req":if(Xt(R,"x11")){R.emit("x11",j,X,N);return}break;case"signal":if(Xt(R,"signal")){R.emit("signal",j,X,{name:N});return}break;case"auth-agent-req@openssh.com":if(Xt(R,"auth-agent")){R.emit("auth-agent",j,X);return}break;case"shell":if(Xt(R,"shell")){j=()=>{if(ie||R._ending||R._channel)return;ie=!0,k&&C.channelSuccess(R._chanInfo.outgoing.id);let re=new Yr(this,R._chanInfo,{server:!0});return re.subtype=R.subtype=w,R._channel=re,re},R.emit("shell",j,X);return}break;case"exec":if(Xt(R,"exec")){j=()=>{if(ie||R._ending||R._channel)return;ie=!0,k&&C.channelSuccess(R._chanInfo.outgoing.id);let re=new Yr(this,R._chanInfo,{server:!0});return re.subtype=R.subtype=w,R._channel=re,re},R.emit("exec",j,X,{command:N});return}break;case"subsystem":{let re=N==="sftp";if(j=()=>{if(ie||R._ending||R._channel)return;ie=!0,k&&C.channelSuccess(R._chanInfo.outgoing.id);let fe;return re?fe=new Tg(this,R._chanInfo,{server:!0,debug:s}):(fe=new Yr(this,R._chanInfo,{server:!0}),fe.subtype=R.subtype=`${w}:${N}`),R._channel=fe,fe},N==="sftp"){if(Xt(R,"sftp")){R.emit("sftp",j,X);return}re=!1}if(Xt(R,"subsystem")){R.emit("subsystem",j,X,{name:N});return}break}}s&&s(`Automatic rejection of incoming channel request: ${w}`),X&&X()},CHANNEL_EOF:(v,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:(v,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)||$g(this,b,w)},SERVICE_REQUEST:(v,b)=>{if(c===0||l||this.authenticated||b!=="ssh-userauth"){C.disconnect(Gr.SERVICE_NOT_AVAILABLE),t.end();return}l=!0,C.serviceAccept(b)},USERAUTH_REQUEST:(v,b,w,k,N)=>{if(c===0||this.authenticated||f&&(f.username!==b||f.service!==w)||k!=="password"&&k!=="publickey"&&k!=="hostbased"&&k!=="keyboard-interactive"&&k!=="none"||u.length===Fg){C.disconnect(Gr.PROTOCOL_ERROR),t.end();return}else if(w!=="ssh-connection"){C.disconnect(Gr.SERVICE_NOT_AVAILABLE),t.end();return}let R;switch(k){case"keyboard-interactive":R=new Hs(C,b,w,k,N,$);break;case"publickey":R=new ic(C,b,w,k,N,$);break;case"hostbased":R=new sc(C,b,w,k,N,$);break;case"password":if(f&&f instanceof Qs&&f._changeCb){let ie=f._changeCb;f._changeCb=void 0,ie(N.newPassword);return}R=new Qs(C,b,w,k,N,$);break;case"none":R=new nr(C,b,w,k,$);break}if(f)if(f._initialResponse)f._multistep&&!f._finalResponse&&(f._cleanup&&f._cleanup(),f.emit("abort"));else return u.push(R);f=R,Xt(this,"authentication")?this.emit("authentication",f):f.reject()},USERAUTH_INFO_RESPONSE:(v,b)=>{f&&f instanceof Hs&&f._onInfoResponse(b)},GLOBAL_REQUEST:(v,b,w,k)=>{let N={type:null,buf:null};function R(ie,j){N.type=ie,N.buf=j,F()}if(w&&y.push(N),(b==="tcpip-forward"||b==="cancel-tcpip-forward"||b==="no-more-sessions@openssh.com"||b==="streamlocal-forward@openssh.com"||b==="cancel-streamlocal-forward@openssh.com")&&Xt(this,"request")&&this.authenticated){let ie,j;if(w){let X=!1;ie=re=>{if(X)return;X=!0;let fe;b==="tcpip-forward"&&k.bindPort===0&&typeof re=="number"&&(fe=Buffer.allocUnsafe(4),Og(fe,re,0)),R("SUCCESS",fe)},j=()=>{X||(X=!0,R("FAILURE"))}}if(b==="no-more-sessions@openssh.com"){this.noMoreSessions=!0,ie&&ie();return}this.emit("request",ie,j,b,k)}else w&&R("FAILURE")}}});t.pause(),Bg.then(()=>{C.start(),t.on("data",v=>{try{C.parse(v,0,v.length)}catch(b){this.emit("error",b);try{Fs(t)&&t.end()}catch{}}}),t.resume()}).catch(v=>{this.emit("error",v);try{Fs(t)&&t.end()}catch{}}),t.on("error",v=>{v.level="socket",this.emit("error",v)}).once("end",()=>{s&&s("Socket ended"),C.cleanup(),this.emit("end")}).once("close",()=>{s&&s("Socket closed"),C.cleanup(),this.emit("close");let v=new Error("No response from server");this._chanMgr.cleanup(v)});let $=(v,b,w,k)=>{f===v&&!this.authenticated&&(b?(f=void 0,this.authenticated=!0,C.authSuccess(),u=[],this.emit("ready")):(C.authFailure(w,k),u.length&&(f=u.pop(),Xt(this,"authentication")?this.emit("authentication",f):f.reject())))};function F(){for(;y.length>0&&y[0].type;){let v=y.shift();v.type==="SUCCESS"&&C.requestSuccess(v.buf),v.type==="FAILURE"&&C.requestFailure()}}}end(){return this._sock&&Fs(this._sock)&&(this._protocol.disconnect(Gr.BY_APPLICATION),this._sock.end()),this}x11(t,e,r){return rc(this,"x11",{originAddr:t,originPort:e},r),this}forwardOut(t,e,r,i,s){return rc(this,"forwarded-tcpip",{boundAddr:t,boundPort:e,remoteAddr:r,remotePort:i},s),this}openssh_forwardOutStreamLocal(t,e){return rc(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 rc(n,t,e,r){let i=er,s=tr;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,i,s,e);break;case"x11":n._protocol.x11(a,i,s,e);break;case"forwarded-streamlocal@openssh.com":n._protocol.openssh_forwardedStreamLocal(a,i,s,e);break;default:throw new Error(`Unsupported channel type: ${t}`)}}function Hg(n,t){return n-t}oc.exports=dn;oc.exports.IncomingClient=Ws});var hf=lt((CE,df)=>{"use strict";var{createCipheriv:Qg,generateKeyPair:Wg,generateKeyPairSync:qg,getCurves:Kg,randomBytes:lf}=require("crypto"),{Ber:St}=ui(),Vg=Io().pbkdf,{CIPHER_INFO:zg}=Gn(),Gg=16,Yg=16,jg=Kg(),Xg=new Map(Object.entries(zg));function uf(n,t){if(typeof n!="string")throw new TypeError("Key type must be a string");let e={type:"spki",format:"der"},r={type:"pkcs8",format:"der"};switch(n.toLowerCase()){case"rsa":{if(typeof t!="object"||t===null)throw new TypeError("Missing options object for RSA key");let i=t.bits;if(!Number.isInteger(i))throw new TypeError("RSA bits must be an integer");if(i<=0||i>16384)throw new RangeError("RSA bits must be non-zero and <= 16384");return["rsa",{modulusLength:i,publicKeyEncoding:e,privateKeyEncoding:r}]}case"ecdsa":{if(typeof t!="object"||t===null)throw new TypeError("Missing options object for ECDSA key");if(!Number.isInteger(t.bits))throw new TypeError("ECDSA bits must be an integer");let i;switch(t.bits){case 256:i="prime256v1";break;case 384:i="secp384r1";break;case 521:i="secp521r1";break;default:throw new Error("ECDSA bits must be 256, 384, or 521")}if(!jg.includes(i))throw new Error("Unsupported ECDSA bits value");return["ec",{namedCurve:i,publicKeyEncoding:e,privateKeyEncoding:r}]}case"ed25519":return["ed25519",{publicKeyEncoding:e,privateKeyEncoding:r}];default:throw new Error(`Unsupported key type: ${n}`)}}function Jg(n,t,e){switch(n){case"rsa":{let r=new St.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()!==St.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 St.Reader(r.readString(St.OctetString,!0)),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in RSA private key");let i=r.readString(St.Integer,!0),s=r.readString(St.Integer,!0),o=r.readString(St.Integer,!0),a=r.readString(St.Integer,!0),c=r.readString(St.Integer,!0);r.readString(St.Integer,!0),r.readString(St.Integer,!0);let l=r.readString(St.Integer,!0),u=Buffer.from("ssh-rsa"),f=Buffer.allocUnsafe(4+u.length+4+i.length+4+s.length+4+o.length+4+l.length+4+a.length+4+c.length),h=0;f.writeUInt32BE(u.length,h+=0),f.set(u,h+=4),f.writeUInt32BE(i.length,h+=u.length),f.set(i,h+=4),f.writeUInt32BE(s.length,h+=i.length),f.set(s,h+=4),f.writeUInt32BE(o.length,h+=s.length),f.set(o,h+=4),f.writeUInt32BE(l.length,h+=o.length),f.set(l,h+=4),f.writeUInt32BE(a.length,h+=l.length),f.set(a,h+=4),f.writeUInt32BE(c.length,h+=a.length),f.set(c,h+=4);let p=Buffer.allocUnsafe(4+u.length+4+s.length+4+i.length);return h=0,p.writeUInt32BE(u.length,h+=0),p.set(u,h+=4),p.writeUInt32BE(s.length,h+=u.length),p.set(s,h+=4),p.writeUInt32BE(i.length,h+=s.length),p.set(i,h+=4),{sshName:u.toString(),priv:f,pub:p}}case"ec":{let r=new St.Reader(t);if(r.readSequence(),r.readSequence(),r.readOID()!=="1.2.840.10045.2.1")throw new Error("Bad ECDSA public OID");r.readOID();let i=r.readString(St.BitString,!0);{let h=0;for(;h<i.length&&i[h]===0;++h);h>0&&(i=i.slice(h))}if(r=new St.Reader(e),r.readSequence(),r.readInt()!==0)throw new Error("Unsupported version in ECDSA private key");if(r.readSequence(),r.readOID()!=="1.2.840.10045.2.1")throw new Error("Bad ECDSA private OID");let s=r.readOID(),o;switch(s){case"1.2.840.10045.3.1.7":o="nistp256";break;case"1.3.132.0.34":o="nistp384";break;case"1.3.132.0.35":o="nistp521";break;default:throw new Error("Unsupported curve in ECDSA private key")}if(r=new St.Reader(r.readString(St.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(St.OctetString,!0)]),c=Buffer.from(`ecdsa-sha2-${o}`);o=Buffer.from(o);let l=Buffer.allocUnsafe(4+c.length+4+o.length+4+i.length+4+a.length),u=0;l.writeUInt32BE(c.length,u+=0),l.set(c,u+=4),l.writeUInt32BE(o.length,u+=c.length),l.set(o,u+=4),l.writeUInt32BE(i.length,u+=o.length),l.set(i,u+=4),l.writeUInt32BE(a.length,u+=i.length),l.set(a,u+=4);let f=Buffer.allocUnsafe(4+c.length+4+o.length+4+i.length);return u=0,f.writeUInt32BE(c.length,u+=0),f.set(c,u+=4),f.writeUInt32BE(o.length,u+=c.length),f.set(o,u+=4),f.writeUInt32BE(i.length,u+=o.length),f.set(i,u+=4),{sshName:c.toString(),priv:l,pub:f}}case"ed25519":{let r=new St.Reader(t);if(r.readSequence(),r.readSequence(),r.readOID()!=="1.3.101.112")throw new Error("Bad ED25519 public OID");let i=r.readString(St.BitString,!0);{let u=0;for(;u<i.length&&i[u]===0;++u);u>0&&(i=i.slice(u))}if(r=new St.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 St.Reader(r.readString(St.OctetString,!0));let s=r.readString(St.OctetString,!0),o=Buffer.from("ssh-ed25519"),a=Buffer.allocUnsafe(4+o.length+4+i.length+4+(s.length+i.length)),c=0;a.writeUInt32BE(o.length,c+=0),a.set(o,c+=4),a.writeUInt32BE(i.length,c+=o.length),a.set(i,c+=4),a.writeUInt32BE(s.length+i.length,c+=i.length),a.set(s,c+=4),a.set(i,c+=s.length);let l=Buffer.allocUnsafe(4+o.length+4+i.length);return c=0,l.writeUInt32BE(o.length,c+=0),l.set(o,c+=4),l.writeUInt32BE(i.length,c+=o.length),l.set(i,c+=4),{sshName:o.toString(),priv:a,pub:l}}}}function ff(n,t,e,r){let i="new",s,o="";if(typeof r=="object"&&r!==null&&(typeof r.comment=="string"&&r.comment&&(o=r.comment),typeof r.format=="string"&&r.format&&(i=r.format),r.passphrase)){let a;if(typeof r.passphrase=="string")a=Buffer.from(r.passphrase);else if(Buffer.isBuffer(r.passphrase))a=r.passphrase;else throw new Error("Invalid passphrase");if(r.cipher===void 0)throw new Error("Missing cipher name");let c=Xg.get(r.cipher);if(c===void 0)throw new Error("Invalid cipher name");if(i==="new"){let l=Yg;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 u=Buffer.allocUnsafe(c.keyLen+c.ivLen),f=lf(Gg);if(Vg(a,a.length,f,f.length,u,u.length,l)!==0)return new Error("Failed to generate information to encrypt key");let p=Buffer.allocUnsafe(4+f.length+4);{let y=0;p.writeUInt32BE(f.length,y+=0),p.set(f,y+=4),p.writeUInt32BE(l,y+=f.length)}s={cipher:c,cipherName:r.cipher,kdfName:"bcrypt",kdfOptions:p,key:u.slice(0,c.keyLen),iv:u.slice(c.keyLen)}}}switch(i){case"new":{let a=`-----BEGIN OPENSSH PRIVATE KEY-----
16
+ `,c,l=Buffer.from(s?s.cipherName:"none"),u=Buffer.from(s?s.kdfName:"none"),f=s?s.kdfOptions:Buffer.alloc(0),h=s?s.cipher.blockLen:8,p=Jg(n,t,e),y=lf(4),E=Buffer.from(o),S=8+p.priv.length+4+E.length,x=[];for(let F=1;(S+x.length)%h;++F)x.push(F&255);x=Buffer.from(x);let P=Buffer.allocUnsafe(S+x.length),q;{let F=0;P.set(y,F+=0),P.set(y,F+=4),P.set(p.priv,F+=4),P.writeUInt32BE(E.length,F+=p.priv.length),P.set(E,F+=4),P.set(x,F+=E.length)}if(s){let F={authTagLength:s.cipher.authLen},v=Qg(s.cipher.sslName,s.key,s.iv,F);v.setAutoPadding(!1),P=Buffer.concat([v.update(P),v.final()]),s.cipher.authLen>0?q=v.getAuthTag():q=Buffer.alloc(0),s.key.fill(0),s.iv.fill(0)}else q=Buffer.alloc(0);let C=Buffer.from("openssh-key-v1\0"),$=Buffer.allocUnsafe(C.length+4+l.length+4+u.length+4+f.length+4+4+p.pub.length+4+P.length+q.length);{let F=0;$.set(C,F+=0),$.writeUInt32BE(l.length,F+=C.length),$.set(l,F+=4),$.writeUInt32BE(u.length,F+=l.length),$.set(u,F+=4),$.writeUInt32BE(f.length,F+=u.length),$.set(f,F+=4),$.writeUInt32BE(1,F+=f.length),$.writeUInt32BE(p.pub.length,F+=4),$.set(p.pub,F+=4),$.writeUInt32BE(P.length,F+=p.pub.length),$.set(P,F+=4),$.set(q,F+=P.length)}{let F=$.base64Slice(0,$.length),v=F.replace(/.{64}/g,`$&
17
17
  `);F.length&63&&(v+=`
18
18
  `),a+=v}{let F=p.pub.base64Slice(0,p.pub.length);c=`${p.sshName} ${F}${o?` ${o}`:""}`}return a+=`-----END OPENSSH PRIVATE KEY-----
19
- `,{private:a,public:c}}default:throw new Error("Invalid output key format")}}function Xg(){}uf.exports={generateKeyPair:(n,t,e)=>{typeof t=="function"&&(e=t,t=void 0),typeof e!="function"&&(e=Xg);let r=cf(n,t);Hg(...r,(s,i,o)=>{if(s)return e(s);let a;try{a=lf(r[0],i,o,t)}catch(c){return e(c)}e(null,a)})},generateKeyPairSync:(n,t)=>{let e=cf(n,t),{publicKey:r,privateKey:s}=Qg(...e);return lf(e[0],r,s,t)}}});var sc=lt((wE,df)=>{"use strict";var{AgentProtocol:Jg,BaseAgent:Zg,createAgent:eA,CygwinAgent:tA,OpenSSHAgent:nA,PageantAgent:rA}=fa(),{SSHTTPAgent:iA,SSHTTPSAgent:sA}=rf(),{parseKey:oA}=Xn(),{flagsToString:aA,OPEN_MODE:cA,STATUS_CODE:lA,stringToFlags:uA}=vi();df.exports={AgentProtocol:Jg,BaseAgent:Zg,createAgent:eA,Client:Ja(),CygwinAgent:tA,HTTPAgent:iA,HTTPSAgent:sA,OpenSSHAgent:nA,PageantAgent:rA,Server:of(),utils:{parseKey:oA,...ff(),sftp:{flagsToString:aA,OPEN_MODE:cA,STATUS_CODE:lA,stringToFlags:uA}}}});var sp=require("node:events"),op=Yt(sc(),1);var Zh=require("node:events");var hf={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
+ `,{private:a,public:c}}default:throw new Error("Invalid output key format")}}function Zg(){}df.exports={generateKeyPair:(n,t,e)=>{typeof t=="function"&&(e=t,t=void 0),typeof e!="function"&&(e=Zg);let r=uf(n,t);Wg(...r,(i,s,o)=>{if(i)return e(i);let a;try{a=ff(r[0],s,o,t)}catch(c){return e(c)}e(null,a)})},generateKeyPairSync:(n,t)=>{let e=uf(n,t),{publicKey:r,privateKey:i}=qg(...e);return ff(e[0],r,i,t)}}});var ac=lt((kE,pf)=>{"use strict";var{AgentProtocol:eA,BaseAgent:tA,createAgent:nA,CygwinAgent:rA,OpenSSHAgent:iA,PageantAgent:sA}=ha(),{SSHTTPAgent:oA,SSHTTPSAgent:aA}=of(),{parseKey:cA}=Xn(),{flagsToString:lA,OPEN_MODE:uA,STATUS_CODE:fA,stringToFlags:dA}=Ni();pf.exports={AgentProtocol:eA,BaseAgent:tA,createAgent:nA,Client:ec(),CygwinAgent:rA,HTTPAgent:oA,HTTPSAgent:aA,OpenSSHAgent:iA,PageantAgent:sA,Server:cf(),utils:{parseKey:cA,...hf(),sftp:{flagsToString:lA,OPEN_MODE:uA,STATUS_CODE:fA,stringToFlags:dA}}}});var ap=require("node:events"),cp=Yt(ac(),1);var tp=require("node:events");var mf={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
20
20
  `,exitCode:1};let r=e[0];if(!r)return{stderr:`Usage: adduser <username>
21
21
  `,exitCode:1};if(t.users.listUsers().includes(r))return{stderr:`adduser: user '${r}' already exists
22
- `,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
23
- `,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
24
- `,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(`
22
+ `,exitCode:1};let i="",s="new";return{sudoChallenge:{username:r,targetUser:r,commandLine:null,loginShell:!1,prompt:"New password: ",mode:"passwd",onPassword:async(a,c)=>s==="new"?a.length<1?{result:{stderr:`adduser: password cannot be empty
23
+ `,exitCode:1}}:(i=a,s="retype",{result:null,nextPrompt:"Retype new password: "}):a!==i?{result:{stderr:`adduser: passwords do not match \u2014 user not created
24
+ `,exitCode:1}}:(await c.users.addUser(r,i),{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(`
25
25
  `)}
26
- `,exitCode:0}})},exitCode:0}}};function pf(n){return Array.isArray(n)?n:[n]}function Ws(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 fA(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:u}=Ws(a,l);if(u){c=!0;break}}if(!c){for(let l of r){let u=Ws(a,l);if(u.matched){c=!0,u.inlineValue===null&&o+1<n.length&&(o+=1);break}}c||s.push(a)}}return s}function ae(n,t){let e=pf(t);for(let r of n)for(let s of e)if(Ws(r,s).matched)return!0;return!1}function an(n,t){let e=pf(t);for(let r=0;r<n.length;r+=1){let s=n[r];for(let i of e){let o=Ws(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 rr(n,t,e={}){return fA(n,e)[t]}function en(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 f=n[c+1];f&&!f.startsWith("-")?(r.set(l,f),c+=1):r.set(l,"");continue}let u=Array.from(o).find(f=>l.startsWith(`${f}=`));if(u){r.set(u,l.slice(u.length+1));continue}s.push(l)}return{flags:e,flagsWithValues:r,positionals:s}}var mf={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(`
27
- `)||"",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(`
28
- `)||void 0,exitCode:0}}},gf={name:"unalias",description:"Remove alias definitions",category:"shell",params:["<name...> | -a"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};if(ae(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 xn=Yt(require("node:path"),1),dA=["/.virtual-env-js/.auth","/etc/htpasswd"];function he(n,t,e){if(!t||t.trim()==="")return n;if(t.startsWith("~")){let r=e??"/root";return xn.posix.normalize(`${r}${t.slice(1)}`)}return t.startsWith("/")?xn.posix.normalize(t):xn.posix.normalize(xn.posix.join(n,t))}function hA(n){let t=n.startsWith("/")?xn.posix.normalize(n):xn.posix.normalize(`/${n}`);return dA.some(e=>t===e||t.startsWith(`${e}/`))}function Fe(n,t,e){if(n!=="root"&&hA(t))throw new Error(`${e}: permission denied: ${t}`)}function Af(n){let e=(n.split("?")[0]?.split("#")[0]??n).split("/").filter(Boolean).pop();return e&&e.length>0?e:"index.html"}function pA(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 yf(n,t,e){let r=he(t,e);if(n.exists(r))return r;let s=xn.posix.dirname(r),i=xn.posix.basename(r),o=n.list(s),a=o.filter(l=>l.toLowerCase()===i.toLowerCase());if(a.length===1)return xn.posix.join(s,a[0]);let c=o.filter(l=>pA(l.toLowerCase(),i.toLowerCase())<=1);return c.length===1?xn.posix.join(s,c[0]):r}function Yr(n){return n.packageManager}var Ef={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=Yr(t);if(!r)return{stderr:"apt: package manager not initialised",exitCode:1};let s=n[0]?.toLowerCase(),i=n.slice(1),o=ae(i,["-q","--quiet","-qq"]),a=ae(i,["--purge"]),c=i.filter(u=>!u.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)
29
- 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:u,exitCode:f}=r.install(c,{quiet:o});return{stdout:u||void 0,exitCode:f}}case"remove":case"purge":{if(c.length===0)return{stderr:"apt: no packages specified",exitCode:1};let{output:u,exitCode:f}=r.remove(c,{purge:s==="purge"||a,quiet:o});return{stdout:u||void 0,exitCode:f}}case"update":return{stdout:["Hit:1 fortune://packages.fortune.local nyx InRelease","Hit:2 fortune://security.fortune.local nyx-security InRelease","Reading package lists... Done","Building dependency tree... Done","Reading state information... Done","All packages are up to date."].join(`
26
+ `,exitCode:0}})},exitCode:0}}};function gf(n){return Array.isArray(n)?n:[n]}function qs(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 hA(n,t={}){let e=new Set(t.flags??[]),r=new Set(t.flagsWithValue??[]),i=[],s=!1;for(let o=0;o<n.length;o+=1){let a=n[o];if(s){i.push(a);continue}if(a==="--"){s=!0;continue}let c=!1;for(let l of e){let{matched:u}=qs(a,l);if(u){c=!0;break}}if(!c){for(let l of r){let u=qs(a,l);if(u.matched){c=!0,u.inlineValue===null&&o+1<n.length&&(o+=1);break}}c||i.push(a)}}return i}function ae(n,t){let e=gf(t);for(let r of n)for(let i of e)if(qs(r,i).matched)return!0;return!1}function an(n,t){let e=gf(t);for(let r=0;r<n.length;r+=1){let i=n[r];for(let s of e){let o=qs(i,s);if(!o.matched)continue;if(o.inlineValue!==null)return o.inlineValue;let a=n[r+1];return a!==void 0&&a!=="--"?a:!0}}}function rr(n,t,e={}){return hA(n,e)[t]}function en(n,t={}){let e=new Set,r=new Map,i=[],s=new Set(t.flags??[]),o=new Set(t.flagsWithValue??[]),a=!1;for(let c=0;c<n.length;c+=1){let l=n[c];if(a){i.push(l);continue}if(l==="--"){a=!0;continue}if(s.has(l)){e.add(l);continue}if(o.has(l)){let f=n[c+1];f&&!f.startsWith("-")?(r.set(l,f),c+=1):r.set(l,"");continue}let u=Array.from(o).find(f=>l.startsWith(`${f}=`));if(u){r.set(u,l.slice(u.length+1));continue}i.push(l)}return{flags:e,flagsWithValues:r,positionals:i}}var Af={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(([i])=>i.startsWith("__alias_")).map(([i,s])=>`alias ${i.slice(8)}='${s}'`).join(`
27
+ `)||"",exitCode:0};let e=[];for(let r of n){let i=r.indexOf("=");if(i===-1){let s=t.vars[`__alias_${r}`];if(s)e.push(`alias ${r}='${s}'`);else return{stderr:`alias: ${r}: not found`,exitCode:1}}else{let s=r.slice(0,i),o=r.slice(i+1).replace(/^['"]|['"]$/g,"");t.vars[`__alias_${s}`]=o}}return{stdout:e.join(`
28
+ `)||void 0,exitCode:0}}},yf={name:"unalias",description:"Remove alias definitions",category:"shell",params:["<name...> | -a"],run:({args:n,env:t})=>{if(!t)return{exitCode:0};if(ae(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 xn=Yt(require("node:path"),1),pA=["/.virtual-env-js/.auth","/etc/htpasswd"];function he(n,t,e){if(!t||t.trim()==="")return n;if(t.startsWith("~")){let r=e??"/root";return xn.posix.normalize(`${r}${t.slice(1)}`)}return t.startsWith("/")?xn.posix.normalize(t):xn.posix.normalize(xn.posix.join(n,t))}function mA(n){let t=n.startsWith("/")?xn.posix.normalize(n):xn.posix.normalize(`/${n}`);return pA.some(e=>t===e||t.startsWith(`${e}/`))}function Fe(n,t,e){if(n!=="root"&&mA(t))throw new Error(`${e}: permission denied: ${t}`)}function Ef(n){let e=(n.split("?")[0]?.split("#")[0]??n).split("/").filter(Boolean).pop();return e&&e.length>0?e:"index.html"}function gA(n,t){let e=Array.from({length:n.length+1},()=>Array(t.length+1).fill(0));for(let r=0;r<=n.length;r+=1)e[r][0]=r;for(let r=0;r<=t.length;r+=1)e[0][r]=r;for(let r=1;r<=n.length;r+=1)for(let i=1;i<=t.length;i+=1){let s=n[r-1]===t[i-1]?0:1;e[r][i]=Math.min(e[r-1][i]+1,e[r][i-1]+1,e[r-1][i-1]+s)}return e[n.length][t.length]}function _f(n,t,e){let r=he(t,e);if(n.exists(r))return r;let i=xn.posix.dirname(r),s=xn.posix.basename(r),o=n.list(i),a=o.filter(l=>l.toLowerCase()===s.toLowerCase());if(a.length===1)return xn.posix.join(i,a[0]);let c=o.filter(l=>gA(l.toLowerCase(),s.toLowerCase())<=1);return c.length===1?xn.posix.join(i,c[0]):r}function jr(n){return n.packageManager}var bf={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=jr(t);if(!r)return{stderr:"apt: package manager not initialised",exitCode:1};let i=n[0]?.toLowerCase(),s=n.slice(1),o=ae(s,["-q","--quiet","-qq"]),a=ae(s,["--purge"]),c=s.filter(u=>!u.startsWith("-"));if(["install","remove","purge","upgrade","update"].includes(i??"")&&e!=="root")return{stderr:`E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
29
+ E: Unable to acquire the dpkg frontend lock, are you root?`,exitCode:100};switch(i){case"install":{if(c.length===0)return{stderr:"apt: no packages specified",exitCode:1};let{output:u,exitCode:f}=r.install(c,{quiet:o});return{stdout:u||void 0,exitCode:f}}case"remove":case"purge":{if(c.length===0)return{stderr:"apt: no packages specified",exitCode:1};let{output:u,exitCode:f}=r.remove(c,{purge:i==="purge"||a,quiet:o});return{stdout:u||void 0,exitCode:f}}case"update":return{stdout:["Hit:1 fortune://packages.fortune.local nyx InRelease","Hit:2 fortune://security.fortune.local nyx-security InRelease","Reading package lists... Done","Building dependency tree... Done","Reading state information... Done","All packages are up to date."].join(`
30
30
  `),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(`
31
31
  `),exitCode:0};case"search":{let u=c[0];if(!u)return{stderr:"apt: search requires a term",exitCode:1};let f=r.search(u);return f.length===0?{stdout:`Sorting... Done
32
32
  Full Text Search... Done
@@ -34,101 +34,101 @@ Full Text Search... Done
34
34
  Full Text Search... Done
35
35
  ${f.map(p=>`${p.name}/${p.section??"misc"} ${p.version} amd64
36
36
  ${p.shortDesc??p.description}`).join(`
37
- `)}`,exitCode:0}}case"show":{let u=c[0];if(!u)return{stderr:"apt: show requires a package name",exitCode:1};let f=r.show(u);return f?{stdout:f,exitCode:0}:{stderr:`N: Unable to locate package ${u}`,exitCode:100}}case"list":{if(ae(i,["--installed"])){let p=r.listInstalled();return p.length===0?{stdout:`Listing... Done
37
+ `)}`,exitCode:0}}case"show":{let u=c[0];if(!u)return{stderr:"apt: show requires a package name",exitCode:1};let f=r.show(u);return f?{stdout:f,exitCode:0}:{stderr:`N: Unable to locate package ${u}`,exitCode:100}}case"list":{if(ae(s,["--installed"])){let p=r.listInstalled();return p.length===0?{stdout:`Listing... Done
38
38
  (no packages installed)`,exitCode:0}:{stdout:`Listing... Done
39
39
  ${p.map(E=>`${E.name}/${E.section} ${E.version} ${E.architecture} [installed]`).join(`
40
40
  `)}`,exitCode:0}}return{stdout:`Listing... Done
41
41
  ${r.listAvailable().map(p=>`${p.name}/${p.section??"misc"} ${p.version} amd64`).join(`
42
42
  `)}`,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(`
43
- `),exitCode:0}}}},_f={name:"apt-cache",description:"Query the package cache",category:"package",params:["<search|show|policy> [pkg]"],run:({args:n,shell:t})=>{let e=Yr(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(`
44
- `)||"(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 nyx/main amd64 Packages"].join(`
45
- `),exitCode:0}}default:return{stderr:`apt-cache: unknown command '${r??""}'`,exitCode:1}}}};var bf={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=an(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=he(r,c);try{Fe(n,C,"awk"),l=s.vfs.readFile(C)}catch{return{stderr:`awk: ${c}: No such file or directory`,exitCode:1}}}let u=l.split(`
46
- `);u[u.length-1]===""&&u.pop();let f=[],h=a.trim();if(!h.startsWith("{")&&!h.includes("{"))f.push({pattern:h,action:"print $0"});else{let C=/([^{]*)\{([^}]*)\}/g,$=C.exec(h);for(;$!==null;)f.push({pattern:$[1].trim(),action:$[2].trim()}),$=C.exec(h);f.length===0&&f.push({pattern:"",action:h.replace(/[{}]/g,"").trim()})}let p=[],y=f.find(C=>C.pattern==="BEGIN"),E=f.find(C=>C.pattern==="END"),S=f.filter(C=>C.pattern!=="BEGIN"&&C.pattern!=="END");function x(C){return i===" "?C.trim().split(/\s+/).filter(Boolean):C.split(i)}function P(C,$,F){let v=x($),b=v.length,w=N=>{if(N=N.trim(),N==="NR")return String(F);if(N==="NF")return String(b);if(N==="$0")return $;if(N==="$NF")return v[b-1]??"";if(/^\$\d+$/.test(N))return v[parseInt(N.slice(1),10)-1]??"";let R=N.replace(/\bNR\b/g,String(F)).replace(/\bNF\b/g,String(b));if(/^[\d\s+\-*/()]+$/.test(R))try{return String(Function(`"use strict"; return (${R});`)())}catch{}return N.replace(/"/g,"")},k=C.split(";").map(N=>N.trim()).filter(Boolean);for(let N of k)if(N==="print"||N==="print $0")p.push($);else if(N.startsWith("print ")){let R=N.slice(6).split(/\s*,\s*/);p.push(R.map(w).join(" "))}}function q(C,$,F){if(!C||C==="1")return!0;let v=C.match(/^NR\s*([=!<>]=?|==)\s*(\d+)$/);if(v){let k=v[1],N=parseInt(v[2],10);switch(k){case"==":return F===N;case"!=":return F!==N;case">":return F>N;case">=":return F>=N;case"<":return F<N;case"<=":return F<=N}}let b=C.match(/^NR%(\d+)==(\d+)$/);if(b)return F%parseInt(b[1],10)===parseInt(b[2],10);if(C.startsWith("/")&&C.endsWith("/"))try{return new RegExp(C.slice(1,-1)).test($)}catch{return!1}let w=C.match(/^\$(\d+)~\/(.*)\/$/);if(w){let N=x($)[parseInt(w[1],10)-1]??"";try{return new RegExp(w[2]).test(N)}catch{return!1}}return!1}y&&P(y.action,"",0);for(let C=1;C<=u.length;C++){let $=u[C-1];for(let F of S)q(F.pattern,$,C)&&P(F.action,$,C)}return E&&P(E.action,"",u.length+1),{stdout:p.join(`
43
+ `),exitCode:0}}}},Sf={name:"apt-cache",description:"Query the package cache",category:"package",params:["<search|show|policy> [pkg]"],run:({args:n,shell:t})=>{let e=jr(t);if(!e)return{stderr:"apt-cache: package manager not initialised",exitCode:1};let r=n[0]?.toLowerCase(),i=n[1];switch(r){case"search":return i?{stdout:e.search(i).map(o=>`${o.name} - ${o.shortDesc??o.description}`).join(`
44
+ `)||"(no results)",exitCode:0}:{stderr:"Need a search term",exitCode:1};case"show":{if(!i)return{stderr:"Need a package name",exitCode:1};let s=e.show(i);return s?{stdout:s,exitCode:0}:{stderr:`N: Unable to locate package ${i}`,exitCode:100}}case"policy":{if(!i)return{stderr:"Need a package name",exitCode:1};let s=e.findInRegistry(i);if(!s)return{stderr:`N: Unable to locate package ${i}`,exitCode:100};let o=e.isInstalled(i);return{stdout:[`${i}:`,` Installed: ${o?s.version:"(none)"}`,` Candidate: ${s.version}`," Version table:",` ${s.version} 500`," 500 fortune://packages.fortune.local nyx/main amd64 Packages"].join(`
45
+ `),exitCode:0}}default:return{stderr:`apt-cache: unknown command '${r??""}'`,exitCode:1}}}};var xf={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:i})=>{let s=an(t,["-F"])??" ",o=t.filter(C=>!C.startsWith("-")&&C!==s),a=o[0],c=o[1];if(!a)return{stderr:"awk: no program",exitCode:1};let l=e??"";if(c){let C=he(r,c);try{Fe(n,C,"awk"),l=i.vfs.readFile(C)}catch{return{stderr:`awk: ${c}: No such file or directory`,exitCode:1}}}let u=l.split(`
46
+ `);u[u.length-1]===""&&u.pop();let f=[],h=a.trim();if(!h.startsWith("{")&&!h.includes("{"))f.push({pattern:h,action:"print $0"});else{let C=/([^{]*)\{([^}]*)\}/g,$=C.exec(h);for(;$!==null;)f.push({pattern:$[1].trim(),action:$[2].trim()}),$=C.exec(h);f.length===0&&f.push({pattern:"",action:h.replace(/[{}]/g,"").trim()})}let p=[],y=f.find(C=>C.pattern==="BEGIN"),E=f.find(C=>C.pattern==="END"),S=f.filter(C=>C.pattern!=="BEGIN"&&C.pattern!=="END");function x(C){return s===" "?C.trim().split(/\s+/).filter(Boolean):C.split(s)}function P(C,$,F){let v=x($),b=v.length,w=N=>{if(N=N.trim(),N==="NR")return String(F);if(N==="NF")return String(b);if(N==="$0")return $;if(N==="$NF")return v[b-1]??"";if(/^\$\d+$/.test(N))return v[parseInt(N.slice(1),10)-1]??"";let R=N.replace(/\bNR\b/g,String(F)).replace(/\bNF\b/g,String(b));if(/^[\d\s+\-*/()]+$/.test(R))try{return String(Function(`"use strict"; return (${R});`)())}catch{}return N.replace(/"/g,"")},k=C.split(";").map(N=>N.trim()).filter(Boolean);for(let N of k)if(N==="print"||N==="print $0")p.push($);else if(N.startsWith("print ")){let R=N.slice(6).split(/\s*,\s*/);p.push(R.map(w).join(" "))}}function q(C,$,F){if(!C||C==="1")return!0;let v=C.match(/^NR\s*([=!<>]=?|==)\s*(\d+)$/);if(v){let k=v[1],N=parseInt(v[2],10);switch(k){case"==":return F===N;case"!=":return F!==N;case">":return F>N;case">=":return F>=N;case"<":return F<N;case"<=":return F<=N}}let b=C.match(/^NR%(\d+)==(\d+)$/);if(b)return F%parseInt(b[1],10)===parseInt(b[2],10);if(C.startsWith("/")&&C.endsWith("/"))try{return new RegExp(C.slice(1,-1)).test($)}catch{return!1}let w=C.match(/^\$(\d+)~\/(.*)\/$/);if(w){let N=x($)[parseInt(w[1],10)-1]??"";try{return new RegExp(w[2]).test(N)}catch{return!1}}return!1}y&&P(y.action,"",0);for(let C=1;C<=u.length;C++){let $=u[C-1];for(let F of S)q(F.pattern,$,C)&&P(F.action,$,C)}return E&&P(E.action,"",u.length+1),{stdout:p.join(`
47
47
  `)+(p.length>0?`
48
- `:""),exitCode:0}}};var Sf={name:"base64",description:"Encode/decode base64",category:"text",params:["[-d] [file]"],run:({args:n,stdin:t})=>{let e=ae(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 xf={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=ae(r,["-n","--number"]),o=ae(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=yf(t.vfs,e,h);Fe(n,p,"cat"),c.push(t.vfs.readFile(p))}let l=c.join("");if(!i&&!o)return{stdout:l,exitCode:0};let u=1;return{stdout:l.split(`
48
+ `:""),exitCode:0}}};var wf={name:"base64",description:"Encode/decode base64",category:"text",params:["[-d] [file]"],run:({args:n,stdin:t})=>{let e=ae(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 If={name:"cat",description:"Concatenate and print files",category:"files",params:["[-n] [-b] <file...>"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=ae(r,["-n","--number"]),o=ae(r,["-b","--number-nonblank"]),a=r.filter(h=>!h.startsWith("-"));if(a.length===0&&i!==void 0)return{stdout:i,exitCode:0};if(a.length===0)return{stderr:"cat: missing file operand",exitCode:1};let c=[];for(let h of a){let p=_f(t.vfs,e,h);Fe(n,p,"cat"),c.push(t.vfs.readFile(p))}let l=c.join("");if(!s&&!o)return{stdout:l,exitCode:0};let u=1;return{stdout:l.split(`
49
49
  `).map(h=>o&&h.trim()===""?h:`${String(u++).padStart(6)} ${h}`).join(`
50
- `),exitCode:0}}};async function wf(n,t,e,r,s,i,o){let a={exitCode:0},c=[],l=s,u=0;for(;u<n.length;){let h=n[u];if(a=await mA(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(;u<n.length&&n[u]?.op==="&&";)u++}else if(p==="||"&&(a.exitCode??0)===0)for(;u<n.length&&n[u]?.op==="||";)u++}u++}let f=c.join("");return{...a,stdout:f||a.stdout,nextCwd:l!==s?l:void 0}}async function mA(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?gA(n.commands[0],t,e,r,s,i,a):AA(n.commands,t,e,r,s,i,a)}async function gA(n,t,e,r,s,i,o){let a;if(n.inputFile){let l=he(s,n.inputFile);try{a=i.vfs.readFile(l)}catch{return{stderr:`${n.inputFile}: No such file or directory`,exitCode:1}}}let c=await Xr(n.name,n.args,t,e,r,s,i,a,o);if(n.outputFile){let l=he(s,n.outputFile),u=c.stdout||"";try{if(n.appendOutput){let f=(()=>{try{return i.vfs.readFile(l)}catch{return""}})();i.writeFileAsUser(t,l,f+u)}else i.writeFileAsUser(t,l,u);return{...c,stdout:""}}catch{return{...c,stderr:`Failed to write to ${n.outputFile}`,exitCode:1}}}return c}async function AA(n,t,e,r,s,i,o){let a="",c=0;for(let l=0;l<n.length;l++){let u=n[l];if(l===0&&u.inputFile){let h=he(s,u.inputFile);try{a=i.vfs.readFile(h)}catch{return{stderr:`${u.inputFile}: No such file or directory`,exitCode:1}}}let f=await Xr(u.name,u.args,t,e,r,s,i,a,o);if(c=f.exitCode??0,l===n.length-1&&u.outputFile){let h=he(s,u.outputFile),p=f.stdout||"";try{if(u.appendOutput){let y=(()=>{try{return i.vfs.readFile(h)}catch{return""}})();i.writeFileAsUser(t,h,y+p)}else i.writeFileAsUser(t,h,p);a=""}catch{return{stderr:`Failed to write to ${u.outputFile}`,exitCode:1}}}else a=f.stdout||"";if(f.stderr&&c!==0)return{stderr:f.stderr,exitCode:c};if(f.closeSession||f.switchUser)return f}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(!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 If(n){let t=n.trim();if(!t)return{statements:[],isValid:!0};try{return{statements:yA(t),isValid:!0}}catch(e){return{statements:[],isValid:!1,error:e.message}}}function yA(n){let t=EA(n),e=[];for(let r of t){let i={pipeline:{commands:_A(r.text.trim()),isValid:!0}};r.op&&(i.op=r.op),e.push(i)}return e}function EA(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 _A(n){return bA(n).map(SA)}function bA(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 SA(n){let t=Di(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 u=e[0]??"";return{name:/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.test(u)?u:u.toLowerCase(),args:e.slice(1),inputFile:r,outputFile:s,appendOutput:i,stderrFile:a,stderrAppend:c,stderrToStdout:l}}function xA(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 uc(n,t){let e=n.trim();if(e.length===0||e.length>1024)return NaN;let r=xA(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 y=f();return r[s]?.type!=="rparen"?NaN:(s++,y)}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 y=c();p=p**y}return p},u=()=>{let p=l();for(;;){let y=i();if(y?.type==="mul"){o(),p*=l();continue}if(y?.type==="div"){o();let E=l();p=E===0?NaN:p/E;continue}if(y?.type==="mod"){o();let E=l();p=E===0?NaN:p%E;continue}return p}},f=()=>{let p=u();for(;;){let y=i();if(y?.type==="plus"){o(),p+=u();continue}if(y?.type==="minus"){o(),p-=u();continue}return p}},h=f();return!Number.isFinite(h)||s!==r.length?NaN:Math.trunc(h)}function wA(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 Ks(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 u=s.slice(0,a),f=s.slice(a+1,c),h=s.slice(c+1),p=f.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.-?(\d+))?$/)||f.match(/^([a-z])\.\.([a-z])$/);if(p){let x=[];if(/\d/.test(p[1])){let C=parseInt(p[1],10),$=parseInt(p[2],10),F=p[3]?parseInt(p[3],10):1,v=C<=$?F:-F;for(let b=C;C<=$?b<=$:b>=$;b+=v)x.push(String(b))}else{let C=p[1].charCodeAt(0),$=p[2].charCodeAt(0),F=C<=$?1:-1;for(let v=C;C<=$?v<=$:v>=$;v+=F)x.push(String.fromCharCode(v))}let P=x.map(C=>`${u}${C}${h}`),q=[];for(let C of P)if(q.push(...r(C,i+1)),q.length>256)return[s];return q}let y=[],E="",S=0;for(let x of f)x==="{"?(S++,E+=x):x==="}"?(S--,E+=x):x===","&&S===0?(y.push(E),E=""):E+=x;if(y.push(E),y.length>1){let x=[];for(let P of y)if(x.push(...r(`${u}${P}${h}`,i+1)),x.length>256)return[s];return x}break}}return[s]}return r(n,0)}function IA(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=uc(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 qs(n,t,e=0,r){let s=r??t.HOME??"/home/user";return wA(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=IA(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 Vs(n,t,e,r){let s="__shellExpandDepth",o=Number(t[s]??"0");if(o>=8)return qs(n,t,e);t[s]=String(o+1);try{if(n.includes("$(")){let a="",c=!1,l=0;for(;l<n.length;){let u=n[l];if(u==="'"&&!c){c=!0,a+=u,l++;continue}if(u==="'"&&c){c=!1,a+=u,l++;continue}if(!c&&u==="$"&&n[l+1]==="("){if(n[l+2]==="("){a+=u,l++;continue}let f=0,h=l+1;for(;h<n.length;){if(n[h]==="(")f++;else if(n[h]===")"&&(f--,f===0))break;h++}let p=n.slice(l+2,h).trim(),y=(await r(p)).replace(/\n$/,"");a+=y,l=h+1;continue}a+=u,l++}n=a}return qs(n,t,e)}finally{o<=0?delete t[s]:t[s]=String(o)}}function Pt(n){return n==="root"?"/root":`/home/${n}`}function jr(n,t){return{vars:{PATH:"/usr/local/bin:/usr/bin:/bin",HOME:Pt(n),USER:n,LOGNAME:n,SHELL:"/bin/sh",TERM:"xterm-256color",HOSTNAME:t,PS1:"\\u@\\h:\\w\\$ "},lastExitCode:0}}function Cf(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 Xr(n,t,e,r,s,i,o,a,c){let l=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/,u=[n,...t],f=0;for(;f<u.length&&l.test(u[f]);)f+=1;if(f>0){let y=u.slice(0,f).map(x=>x.match(l)),E=u.slice(f),S=[];for(let[,x,P]of y)S.push([x,c.vars[x]]),c.vars[x]=P;if(E.length===0)return{exitCode:0};try{return await Xr(E[0],E.slice(1),e,r,s,i,o,a,c)}finally{for(let[x,P]of S)P===void 0?delete c.vars[x]:c.vars[x]=P}}let h=c.vars[`__alias_${n}`];if(h)return wt(`${h} ${t.join(" ")}`,e,r,s,i,o,a,c);let p=wn(n);if(!p){let y=Cf(n,c,o,e);if(y){let E=o.vfs.readFile(y),S=E.match(/exec\s+builtin\s+(\S+)/);if(S){let P=wn(S[1]);if(P)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})}let x=wn("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(y){return{stderr:y instanceof Error?y.message:"Command failed",exitCode:1}}}async function wt(n,t,e,r,s,i,o,a){let c=n.trim();if(c.length===0)return{exitCode:0};let l=a??jr(t,e),f=Di(c)[0]?.toLowerCase()??"",h=l.vars[`__alias_${f}`],p=h?c.replace(f,h):c,y=/\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(y&&f!=="sh"&&f!=="bash"||E){if(y&&f!=="sh"&&f!=="bash"){let v=wn("sh");if(v)return await v.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 F=If(p);if(!F.isValid)return{stderr:F.error||"Syntax error",exitCode:1};try{return await wf(F.statements,t,e,r,s,i,l)}catch(v){return{stderr:v instanceof Error?v.message:"Execution failed",exitCode:1}}}let S=await Vs(p,l.vars,l.lastExitCode,F=>wt(F,t,e,r,s,i,void 0,l).then(v=>v.stdout??"")),x=Di(S.trim());if(x.length===0)return{exitCode:0};if(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.test(x[0]))return Xr(x[0],x.slice(1),t,e,r,s,i,o,l);let q=x[0]?.toLowerCase()??"",C=x.slice(1).flatMap(Ks),$=wn(q);if(!$){let F=Cf(q,l,i,t);if(F){let v=i.vfs.readFile(F),b=v.match(/exec\s+builtin\s+(\S+)/);if(b){let k=b[1],N=wn(k);if(N)return await N.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:[q,...C].join(" "),mode:r,args:C,stdin:o,cwd:s,shell:i,env:l})}let w=wn("sh");if(w)return await w.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(v)}`,mode:r,args:["-c",v,"--",...C],stdin:o,cwd:s,shell:i,env:l})}return{stderr:`${q}: command not found`,exitCode:127}}try{return await $.run({authUser:t,hostname:e,activeSessions:i.users.listActiveSessions(),rawInput:S,mode:r,args:C,stdin:o,cwd:s,shell:i,env:l})}catch(F){return{stderr:F instanceof Error?F.message:"Command failed",exitCode:1}}}var kf={name:"cd",description:"Change directory",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=he(e,r[0]??"~",Pt(n));return Fe(n,s,"cd"),t.vfs.stat(s).type!=="directory"?{stderr:`cd: not a directory: ${s}`,exitCode:1}:{nextCwd:s,exitCode:0}}};function CA(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,u=a===""||a==="a"?["u","g","o"]:a.split(""),f={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 u)for(let p of l.split("")){let y=f[h]?.[p];if(y!==void 0){if(c==="+")s|=y;else if(c==="-")s&=~y;else if(c==="="){let E=Object.values(f[h]??{}).reduce((S,x)=>S|x,0);s=s&~E|y}}}}return s}var vf={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=he(e,i);try{if(Fe(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,u=CA(l,s);if(u===null)return{stderr:`chmod: invalid mode: ${s}`,exitCode:1};a=u}return t.vfs.chmod(o,a),{exitCode:0}}catch(a){return{stderr:`chmod: ${a instanceof Error?a.message:String(a)}`,exitCode:1}}}};var Nf={name:"clear",description:"Clear the terminal screen",category:"shell",params:[],run:()=>({clearScreen:!0,stdout:"",exitCode:0})};var Bf={name:"cp",description:"Copy files or directories",category:"files",params:["[-r] <source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=ae(r,["-r","-R","--recursive"]),i=r.filter(u=>!u.startsWith("-")),[o,a]=i;if(!o||!a)return{stderr:"cp: missing operand",exitCode:1};let c=he(e,o),l=he(e,a);try{if(Fe(n,c,"cp"),Fe(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 f=(p,y)=>{t.vfs.mkdir(y,493);for(let E of t.vfs.list(p)){let S=`${p}/${E}`,x=`${y}/${E}`;if(t.vfs.stat(S).type==="directory")f(S,x);else{let q=t.vfs.readFileRaw(S);t.writeFileAsUser(n,x,q)}}},h=t.vfs.exists(l)&&t.vfs.stat(l).type==="directory"?`${l}/${o.split("/").pop()}`:l;f(c,h)}else{let f=t.vfs.exists(l)&&t.vfs.stat(l).type==="directory"?`${l}/${o.split("/").pop()}`:l,h=t.vfs.readFileRaw(c);t.writeFileAsUser(n,f,h)}return{exitCode:0}}catch(u){return{stderr:`cp: ${u instanceof Error?u.message:String(u)}`,exitCode:1}}}};var Rf={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}=en(e,{flagsWithValue:["-o","--output","-X","--request","-d","--data","-H","--header","-u","--user"]});if(ae(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(`
51
- `),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,u=s.get("-H")??s.get("--header")??null,f=ae(e,["-s","--silent"]),h=ae(e,["-I","--head"]),p=ae(e,["-L","--location"]),y=ae(e,["-v","--verbose"]),E={"User-Agent":"curl/7.88.1"};if(u){let $=u.indexOf(":");$!==-1&&(E[u.slice(0,$).trim()]=u.slice($+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 P=[];y&&(P.push(`* Trying ${o}...`,"* Connected"),P.push(`> ${S} / HTTP/1.1`,`> Host: ${new URL(o).host}`));let q;try{let $=o.startsWith("http://")||o.startsWith("https://")?o:`http://${o}`;q=await fetch($,x)}catch($){return{stderr:`curl: (6) Could not resolve host: ${$ instanceof Error?$.message:String($)}`,exitCode:6}}if(y&&P.push(`< HTTP/1.1 ${q.status} ${q.statusText}`),h){let $=[`HTTP/1.1 ${q.status} ${q.statusText}`];for(let[F,v]of q.headers.entries())$.push(`${F}: ${v}`);return{stdout:`${$.join(`\r
50
+ `),exitCode:0}}};async function Cf(n,t,e,r,i,s,o){let a={exitCode:0},c=[],l=i,u=0;for(;u<n.length;){let h=n[u];if(a=await AA(h.pipeline,t,e,r,l,s,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(;u<n.length&&n[u]?.op==="&&";)u++}else if(p==="||"&&(a.exitCode??0)===0)for(;u<n.length&&n[u]?.op==="||";)u++}u++}let f=c.join("");return{...a,stdout:f||a.stdout,nextCwd:l!==i?l:void 0}}async function AA(n,t,e,r,i,s,o){if(!n.isValid)return{stderr:n.error||"Syntax error",exitCode:1};if(n.commands.length===0)return{exitCode:0};let a=o??{vars:{},lastExitCode:0};return n.commands.length===1?yA(n.commands[0],t,e,r,i,s,a):EA(n.commands,t,e,r,i,s,a)}async function yA(n,t,e,r,i,s,o){let a;if(n.inputFile){let l=he(i,n.inputFile);try{a=s.vfs.readFile(l)}catch{return{stderr:`${n.inputFile}: No such file or directory`,exitCode:1}}}let c=await Jr(n.name,n.args,t,e,r,i,s,a,o);if(n.outputFile){let l=he(i,n.outputFile),u=c.stdout||"";try{if(n.appendOutput){let f=(()=>{try{return s.vfs.readFile(l)}catch{return""}})();s.writeFileAsUser(t,l,f+u)}else s.writeFileAsUser(t,l,u);return{...c,stdout:""}}catch{return{...c,stderr:`Failed to write to ${n.outputFile}`,exitCode:1}}}return c}async function EA(n,t,e,r,i,s,o){let a="",c=0;for(let l=0;l<n.length;l++){let u=n[l];if(l===0&&u.inputFile){let h=he(i,u.inputFile);try{a=s.vfs.readFile(h)}catch{return{stderr:`${u.inputFile}: No such file or directory`,exitCode:1}}}let f=await Jr(u.name,u.args,t,e,r,i,s,a,o);if(c=f.exitCode??0,l===n.length-1&&u.outputFile){let h=he(i,u.outputFile),p=f.stdout||"";try{if(u.appendOutput){let y=(()=>{try{return s.vfs.readFile(h)}catch{return""}})();s.writeFileAsUser(t,h,y+p)}else s.writeFileAsUser(t,h,p);a=""}catch{return{stderr:`Failed to write to ${u.outputFile}`,exitCode:1}}}else a=f.stdout||"";if(f.stderr&&c!==0)return{stderr:f.stderr,exitCode:c};if(f.closeSession||f.switchUser)return f}return{stdout:a,exitCode:c}}function Ui(n){let t=[],e="",r=!1,i="",s=0;for(;s<n.length;){let o=n[s],a=n[s+1];if((o==='"'||o==="'")&&!r){r=!0,i=o,s++;continue}if(r&&o===i){r=!1,i="",s++;continue}if(r){e+=o,s++;continue}if(o===" "){e&&(t.push(e),e=""),s++;continue}if(!r&&o==="2"&&a===">"){let c=n.slice(s+1);if(c.startsWith(">>&1")||c.startsWith(">> &1")){e&&(t.push(e),e=""),t.push("2>>&1"),s+=5;continue}if(c.startsWith(">&1")){e&&(t.push(e),e=""),t.push("2>&1"),s+=4;continue}if(c.startsWith(">>")){e&&(t.push(e),e=""),t.push("2>>"),s+=3;continue}if(c.startsWith(">")){e&&(t.push(e),e=""),t.push("2>"),s+=2;continue}}if((o===">"||o==="<")&&!r){e&&(t.push(e),e=""),o===">"&&a===">"?(t.push(">>"),s+=2):(t.push(o),s++);continue}e+=o,s++}return e&&t.push(e),t}function kf(n){let t=n.trim();if(!t)return{statements:[],isValid:!0};try{return{statements:_A(t),isValid:!0}}catch(e){return{statements:[],isValid:!1,error:e.message}}}function _A(n){let t=bA(n),e=[];for(let r of t){let s={pipeline:{commands:SA(r.text.trim()),isValid:!0}};r.op&&(s.op=r.op),e.push(s)}return e}function bA(n){let t=[],e="",r=0,i=!1,s="",o=0,a=c=>{e.trim()&&t.push({text:e,op:c}),e=""};for(;o<n.length;){let c=n[o],l=n.slice(o,o+2);if((c==='"'||c==="'")&&!i){i=!0,s=c,e+=c,o++;continue}if(i&&c===s){i=!1,e+=c,o++;continue}if(i){e+=c,o++;continue}if(c==="("){r++,e+=c,o++;continue}if(c===")"){r--,e+=c,o++;continue}if(r>0){e+=c,o++;continue}if(l==="&&"){a("&&"),o+=2;continue}if(l==="||"){a("||"),o+=2;continue}if(c===";"){a(";"),o++;continue}e+=c,o++}return a(),t}function SA(n){return xA(n).map(wA)}function xA(n){let t=[],e="",r=!1,i="";for(let o=0;o<n.length;o++){let a=n[o];if((a==='"'||a==="'")&&!r){r=!0,i=a,e+=a;continue}if(r&&a===i){r=!1,e+=a;continue}if(r){e+=a;continue}if(a==="|"&&n[o+1]!=="|"){if(!e.trim())throw new Error("Syntax error near unexpected token '|'");t.push(e.trim()),e=""}else e+=a}let s=e.trim();if(!s&&t.length>0)throw new Error("Syntax error near unexpected token '|'");return s&&t.push(s),t}function wA(n){let t=Ui(n);if(t.length===0)return{name:"",args:[]};let e=[],r,i,s=!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 >>");i=t[o],s=!0,o++}else if(h===">"){if(o++,o>=t.length)throw new Error("Syntax error: expected filename after >");i=t[o],s=!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 u=e[0]??"";return{name:/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.test(u)?u:u.toLowerCase(),args:e.slice(1),inputFile:r,outputFile:i,appendOutput:s,stderrFile:a,stderrAppend:c,stderrToStdout:l}}function IA(n,t){let e=[],r=0;for(;r<n.length;){let i=n[r];if(/\s/.test(i)){r++;continue}if(i==="+"){e.push({type:"plus"}),r++;continue}if(i==="-"){e.push({type:"minus"}),r++;continue}if(i==="*"){if(n[r+1]==="*"){e.push({type:"pow"}),r+=2;continue}e.push({type:"mul"}),r++;continue}if(i==="/"){e.push({type:"div"}),r++;continue}if(i==="%"){e.push({type:"mod"}),r++;continue}if(i==="("){e.push({type:"lparen"}),r++;continue}if(i===")"){e.push({type:"rparen"}),r++;continue}if(/\d/.test(i)){let s=r+1;for(;s<n.length&&/\d/.test(n[s]);)s++;e.push({type:"number",value:Number(n.slice(r,s))}),r=s;continue}if(/[A-Za-z_]/.test(i)){let s=r+1;for(;s<n.length&&/[A-Za-z0-9_]/.test(n[s]);)s++;let o=n.slice(r,s),a=t[o],c=a===void 0||a===""?0:Number(a);e.push({type:"number",value:Number.isFinite(c)?c:0}),r=s;continue}return[]}return e}function dc(n,t){let e=n.trim();if(e.length===0||e.length>1024)return NaN;let r=IA(e,t);if(r.length===0)return NaN;let i=0,s=()=>r[i],o=()=>r[i++],a=()=>{let p=o();if(!p)return NaN;if(p.type==="number")return p.value;if(p.type==="lparen"){let y=f();return r[i]?.type!=="rparen"?NaN:(i++,y)}return NaN},c=()=>{let p=s();return p?.type==="plus"?(o(),c()):p?.type==="minus"?(o(),-c()):a()},l=()=>{let p=c();for(;s()?.type==="pow";){o();let y=c();p=p**y}return p},u=()=>{let p=l();for(;;){let y=s();if(y?.type==="mul"){o(),p*=l();continue}if(y?.type==="div"){o();let E=l();p=E===0?NaN:p/E;continue}if(y?.type==="mod"){o();let E=l();p=E===0?NaN:p%E;continue}return p}},f=()=>{let p=u();for(;;){let y=s();if(y?.type==="plus"){o(),p+=u();continue}if(y?.type==="minus"){o(),p-=u();continue}return p}},h=f();return!Number.isFinite(h)||i!==r.length?NaN:Math.trunc(h)}function CA(n,t){let e=[],r=0;for(;r<n.length;){let i=n.indexOf("'",r);if(i===-1){e.push(t(n.slice(r)));break}e.push(t(n.slice(r,i)));let s=n.indexOf("'",i+1);if(s===-1){e.push(n.slice(i));break}e.push(n.slice(i,s+1)),r=s+1}return e.join("")}function Vs(n){function r(i,s){if(s>8)return[i];let o=0,a=-1;for(let c=0;c<i.length;c++){let l=i[c];if(l==="{"&&i[c-1]!=="$")o===0&&(a=c),o++;else if(l==="}"&&(o--,o===0&&a!==-1)){let u=i.slice(0,a),f=i.slice(a+1,c),h=i.slice(c+1),p=f.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.-?(\d+))?$/)||f.match(/^([a-z])\.\.([a-z])$/);if(p){let x=[];if(/\d/.test(p[1])){let C=parseInt(p[1],10),$=parseInt(p[2],10),F=p[3]?parseInt(p[3],10):1,v=C<=$?F:-F;for(let b=C;C<=$?b<=$:b>=$;b+=v)x.push(String(b))}else{let C=p[1].charCodeAt(0),$=p[2].charCodeAt(0),F=C<=$?1:-1;for(let v=C;C<=$?v<=$:v>=$;v+=F)x.push(String.fromCharCode(v))}let P=x.map(C=>`${u}${C}${h}`),q=[];for(let C of P)if(q.push(...r(C,s+1)),q.length>256)return[i];return q}let y=[],E="",S=0;for(let x of f)x==="{"?(S++,E+=x):x==="}"?(S--,E+=x):x===","&&S===0?(y.push(E),E=""):E+=x;if(y.push(E),y.length>1){let x=[];for(let P of y)if(x.push(...r(`${u}${P}${h}`,s+1)),x.length>256)return[i];return x}break}}return[i]}return r(n,0)}function kA(n,t){let e="",r=0;for(;r<n.length;){if(n[r]==="$"&&n[r+1]==="("&&n[r+2]==="("){let i=r+3,s=0;for(;i<n.length;){let o=n[i];if(o==="(")s++;else if(o===")"){if(s>0)s--;else if(n[i+1]===")"){let a=n.slice(r+3,i),c=dc(a,t);e+=Number.isNaN(c)?"0":String(c),r=i+2;break}}i++}if(i>=n.length){e+=n.slice(r);break}continue}e+=n[r],r++}return e}function Ks(n,t,e=0,r){let i=r??t.HOME??"/home/user";return CA(n,s=>{let o=s;return o=o.replace(/(^|[\s:])~(\/|$)/g,(a,c,l)=>`${c}${i}${l}`),o=o.replace(/\$\?/g,String(e)),o=o.replace(/\$\$/g,"1"),o=o.replace(/\$#/g,"0"),o=kA(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 zs(n,t,e,r){let i="__shellExpandDepth",o=Number(t[i]??"0");if(o>=8)return Ks(n,t,e);t[i]=String(o+1);try{if(n.includes("$(")){let a="",c=!1,l=0;for(;l<n.length;){let u=n[l];if(u==="'"&&!c){c=!0,a+=u,l++;continue}if(u==="'"&&c){c=!1,a+=u,l++;continue}if(!c&&u==="$"&&n[l+1]==="("){if(n[l+2]==="("){a+=u,l++;continue}let f=0,h=l+1;for(;h<n.length;){if(n[h]==="(")f++;else if(n[h]===")"&&(f--,f===0))break;h++}let p=n.slice(l+2,h).trim(),y=(await r(p)).replace(/\n$/,"");a+=y,l=h+1;continue}a+=u,l++}n=a}return Ks(n,t,e)}finally{o<=0?delete t[i]:t[i]=String(o)}}function Pt(n){return n==="root"?"/root":`/home/${n}`}function Xr(n,t){return{vars:{PATH:"/usr/local/bin:/usr/bin:/bin",HOME:Pt(n),USER:n,LOGNAME:n,SHELL:"/bin/sh",TERM:"xterm-256color",HOSTNAME:t,PS1:"\\u@\\h:\\w\\$ "},lastExitCode:0}}function vf(n,t,e,r){if(n.startsWith("/")){if(!e.vfs.exists(n))return null;try{let s=e.vfs.stat(n);return s.type!=="file"||!(s.mode&73)||(n.startsWith("/sbin/")||n.startsWith("/usr/sbin/"))&&r!=="root"?null:n}catch{return null}}let i=(t.vars.PATH??"/usr/local/bin:/usr/bin:/bin").split(":");for(let s of i){if((s==="/sbin"||s==="/usr/sbin")&&r!=="root")continue;let o=`${s}/${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}var Gs=8,ir=0;async function Jr(n,t,e,r,i,s,o,a,c){if(ir++,ir>Gs)return ir--,{stderr:`${n}: maximum call depth (${Gs}) exceeded`,exitCode:126};try{return await vA(n,t,e,r,i,s,o,a,c)}finally{ir--}}async function vA(n,t,e,r,i,s,o,a,c){let l=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/,u=[n,...t],f=0;for(;f<u.length&&l.test(u[f]);)f+=1;if(f>0){let y=u.slice(0,f).map(x=>x.match(l)),E=u.slice(f),S=[];for(let[,x,P]of y)S.push([x,c.vars[x]]),c.vars[x]=P;if(E.length===0)return{exitCode:0};try{return await Jr(E[0],E.slice(1),e,r,i,s,o,a,c)}finally{for(let[x,P]of S)P===void 0?delete c.vars[x]:c.vars[x]=P}}let h=c.vars[`__alias_${n}`];if(h)return wt(`${h} ${t.join(" ")}`,e,r,i,s,o,a,c);let p=wn(n);if(!p){let y=vf(n,c,o,e);if(y){let E=o.vfs.readFile(y),S=E.match(/exec\s+builtin\s+(\S+)/);if(S){let P=wn(S[1]);return P?await P.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:[n,...t].join(" "),mode:i,args:t,stdin:a,cwd:s,shell:o,env:c}):{stderr:`${n}: exec builtin '${S[1]}' not found`,exitCode:127}}let x=wn("sh");if(x)return await x.run({authUser:e,hostname:r,activeSessions:o.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(E)}`,mode:i,args:["-c",E,"--",...t],stdin:a,cwd:s,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:i,args:t,stdin:a,cwd:s,shell:o,env:c})}catch(y){return{stderr:y instanceof Error?y.message:"Command failed",exitCode:1}}}async function wt(n,t,e,r,i,s,o,a){let c=n.trim();if(c.length===0)return{exitCode:0};let l=a??Xr(t,e);if(ir++,ir>Gs)return ir--,{stderr:`${c.split(" ")[0]}: maximum call depth (${Gs}) exceeded`,exitCode:126};try{let f=Ui(c)[0]?.toLowerCase()??"",h=l.vars[`__alias_${f}`],p=h?c.replace(f,h):c,y=/\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(y&&f!=="sh"&&f!=="bash"||E){if(y&&f!=="sh"&&f!=="bash"){let v=wn("sh");if(v)return await v.run({authUser:t,hostname:e,activeSessions:s.users.listActiveSessions(),rawInput:p,mode:r,args:["-c",p],stdin:void 0,cwd:i,shell:s,env:l})}let F=kf(p);if(!F.isValid)return{stderr:F.error||"Syntax error",exitCode:1};try{return await Cf(F.statements,t,e,r,i,s,l)}catch(v){return{stderr:v instanceof Error?v.message:"Execution failed",exitCode:1}}}let S=await zs(p,l.vars,l.lastExitCode,F=>wt(F,t,e,r,i,s,void 0,l).then(v=>v.stdout??"")),x=Ui(S.trim());if(x.length===0)return{exitCode:0};if(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.test(x[0]))return Jr(x[0],x.slice(1),t,e,r,i,s,o,l);let q=x[0]?.toLowerCase()??"",C=x.slice(1).flatMap(Vs),$=wn(q);if(!$){let F=vf(q,l,s,t);if(F){let v=s.vfs.readFile(F),b=v.match(/exec\s+builtin\s+(\S+)/);if(b){let k=b[1],N=wn(k);if(N)return await N.run({authUser:t,hostname:e,activeSessions:s.users.listActiveSessions(),rawInput:[q,...C].join(" "),mode:r,args:C,stdin:o,cwd:i,shell:s,env:l})}let w=wn("sh");if(w)return await w.run({authUser:t,hostname:e,activeSessions:s.users.listActiveSessions(),rawInput:`sh -c ${JSON.stringify(v)}`,mode:r,args:["-c",v,"--",...C],stdin:o,cwd:i,shell:s,env:l})}return{stderr:`${q}: command not found`,exitCode:127}}try{return await $.run({authUser:t,hostname:e,activeSessions:s.users.listActiveSessions(),rawInput:S,mode:r,args:C,stdin:o,cwd:i,shell:s,env:l})}catch(F){return{stderr:F instanceof Error?F.message:"Command failed",exitCode:1}}}finally{ir--}}var Nf={name:"cd",description:"Change directory",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=he(e,r[0]??"~",Pt(n));return Fe(n,i,"cd"),t.vfs.stat(i).type!=="directory"?{stderr:`cd: not a directory: ${i}`,exitCode:1}:{nextCwd:i,exitCode:0}}};function NA(n,t){let e=/^([ugoa]*)([+\-=])([rwx]*)$/,r=t.split(","),i=n;for(let s of r){let o=s.trim().match(e);if(!o)return null;let[,a="a",c,l=""]=o,u=a===""||a==="a"?["u","g","o"]:a.split(""),f={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 u)for(let p of l.split("")){let y=f[h]?.[p];if(y!==void 0){if(c==="+")i|=y;else if(c==="-")i&=~y;else if(c==="="){let E=Object.values(f[h]??{}).reduce((S,x)=>S|x,0);i=i&~E|y}}}}return i}var Bf={name:"chmod",description:"Change file permissions",category:"files",params:["<mode> <file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let[i,s]=r;if(!i||!s)return{stderr:"chmod: missing operand",exitCode:1};let o=he(e,s);try{if(Fe(n,o,"chmod"),!t.vfs.exists(o))return{stderr:`chmod: ${s}: No such file or directory`,exitCode:1};let a,c=parseInt(i,8);if(!Number.isNaN(c)&&/^[0-7]+$/.test(i))a=c;else{let l=t.vfs.stat(o).mode,u=NA(l,i);if(u===null)return{stderr:`chmod: invalid mode: ${i}`,exitCode:1};a=u}return t.vfs.chmod(o,a),{exitCode:0}}catch(a){return{stderr:`chmod: ${a instanceof Error?a.message:String(a)}`,exitCode:1}}}};var Rf={name:"clear",description:"Clear the terminal screen",category:"shell",params:[],run:()=>({clearScreen:!0,stdout:"",exitCode:0})};var Pf={name:"cp",description:"Copy files or directories",category:"files",params:["[-r] <source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=ae(r,["-r","-R","--recursive"]),s=r.filter(u=>!u.startsWith("-")),[o,a]=s;if(!o||!a)return{stderr:"cp: missing operand",exitCode:1};let c=he(e,o),l=he(e,a);try{if(Fe(n,c,"cp"),Fe(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(!i)return{stderr:`cp: ${o}: is a directory (use -r)`,exitCode:1};let f=(p,y)=>{t.vfs.mkdir(y,493);for(let E of t.vfs.list(p)){let S=`${p}/${E}`,x=`${y}/${E}`;if(t.vfs.stat(S).type==="directory")f(S,x);else{let q=t.vfs.readFileRaw(S);t.writeFileAsUser(n,x,q)}}},h=t.vfs.exists(l)&&t.vfs.stat(l).type==="directory"?`${l}/${o.split("/").pop()}`:l;f(c,h)}else{let f=t.vfs.exists(l)&&t.vfs.stat(l).type==="directory"?`${l}/${o.split("/").pop()}`:l,h=t.vfs.readFileRaw(c);t.writeFileAsUser(n,f,h)}return{exitCode:0}}catch(u){return{stderr:`cp: ${u instanceof Error?u.message:String(u)}`,exitCode:1}}}};var Tf={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:i,positionals:s}=en(e,{flagsWithValue:["-o","--output","-X","--request","-d","--data","-H","--header","-u","--user"]});if(ae(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(`
51
+ `),exitCode:0};let o=s[0];if(!o)return{stderr:"curl: no URL specified",exitCode:1};let a=i.get("-o")??i.get("--output")??null,c=(i.get("-X")??i.get("--request")??"GET").toUpperCase(),l=i.get("-d")??i.get("--data")??null,u=i.get("-H")??i.get("--header")??null,f=ae(e,["-s","--silent"]),h=ae(e,["-I","--head"]),p=ae(e,["-L","--location"]),y=ae(e,["-v","--verbose"]),E={"User-Agent":"curl/7.88.1"};if(u){let $=u.indexOf(":");$!==-1&&(E[u.slice(0,$).trim()]=u.slice($+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 P=[];y&&(P.push(`* Trying ${o}...`,"* Connected"),P.push(`> ${S} / HTTP/1.1`,`> Host: ${new URL(o).host}`));let q;try{let $=o.startsWith("http://")||o.startsWith("https://")?o:`http://${o}`;q=await fetch($,x)}catch($){return{stderr:`curl: (6) Could not resolve host: ${$ instanceof Error?$.message:String($)}`,exitCode:6}}if(y&&P.push(`< HTTP/1.1 ${q.status} ${q.statusText}`),h){let $=[`HTTP/1.1 ${q.status} ${q.statusText}`];for(let[F,v]of q.headers.entries())$.push(`${F}: ${v}`);return{stdout:`${$.join(`\r
52
52
  `)}\r
53
53
  `,exitCode:0}}let C;try{C=await q.text()}catch{return{stderr:"curl: failed to read response body",exitCode:1}}if(a){let $=he(t,a);return Fe(n,$,"curl"),r.writeFileAsUser(n,$,C),f||P.push(` % Total % Received
54
54
  100 ${C.length} 100 ${C.length}`),{stderr:P.join(`
55
55
  `)||void 0,exitCode:q.ok?0:22}}return{stdout:C,stderr:P.length>0?P.join(`
56
- `):void 0,exitCode:q.ok?0:22}}};var Pf={name:"cut",description:"Remove sections from lines",category:"text",params:["-d <delim> -f <fields> [file]"],run:({args:n,stdin:t})=>{let e=an(n,["-d"])??" ",s=(an(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(`
57
- `).map(a=>{let c=a.split(e),l=[];for(let u of s)for(let f=u.from;f<=Math.min(u.to,c.length-1);f++)l.push(c[f]??"");return l.join(e)}).join(`
58
- `),exitCode:0}}};var Tf={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 Of={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=ae(n,["-i"]),r=ae(n,["-r"]),s=ae(n,["-x"]);if(n.filter(a=>!a.startsWith("-")).length===0)return{stdout:Object.entries(t.vars).map(([c,l])=>`declare -- ${c}="${l}"`).join(`
59
- `),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),u=a.slice(c+1);if(e){let f=parseInt(u,10);u=Number.isNaN(f)?"0":String(f)}t.vars[l]=u}}return{exitCode:0}}};var Mf={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
60
- `,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>
61
- `,exitCode:1};if(!e.users.listUsers().includes(s))return{stderr:`deluser: user '${s}' does not exist
62
- `,exitCode:1};if(s==="root")return{stderr:`deluser: cannot remove the root account
63
- `,exitCode:1};if(r)return await e.users.deleteUser(s),{stdout:`Removing user '${s}' ...
56
+ `):void 0,exitCode:q.ok?0:22}}};var Of={name:"cut",description:"Remove sections from lines",category:"text",params:["-d <delim> -f <fields> [file]"],run:({args:n,stdin:t})=>{let e=an(n,["-d"])??" ",i=(an(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(`
57
+ `).map(a=>{let c=a.split(e),l=[];for(let u of i)for(let f=u.from;f<=Math.min(u.to,c.length-1);f++)l.push(c[f]??"");return l.join(e)}).join(`
58
+ `),exitCode:0}}};var Mf={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 Lf={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=ae(n,["-i"]),r=ae(n,["-r"]),i=ae(n,["-x"]);if(n.filter(a=>!a.startsWith("-")).length===0)return{stdout:Object.entries(t.vars).map(([c,l])=>`declare -- ${c}="${l}"`).join(`
59
+ `),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),u=a.slice(c+1);if(e){let f=parseInt(u,10);u=Number.isNaN(f)?"0":String(f)}t.vars[l]=u}}return{exitCode:0}}};var Df={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
60
+ `,exitCode:1};let r=t.includes("-f")||t.includes("--force")||t.includes("-y"),i=t.find(o=>!o.startsWith("-"));if(!i)return{stderr:`Usage: deluser [-f] <username>
61
+ `,exitCode:1};if(!e.users.listUsers().includes(i))return{stderr:`deluser: user '${i}' does not exist
62
+ `,exitCode:1};if(i==="root")return{stderr:`deluser: cannot remove the root account
63
+ `,exitCode:1};if(r)return await e.users.deleteUser(i),{stdout:`Removing user '${i}' ...
64
64
  deluser: done.
65
- `,exitCode:0};let i=async(o,a)=>o.trim()!==s?{result:{stderr:`deluser: confirmation did not match \u2014 user not deleted
66
- `,exitCode:1}}:(await a.users.deleteUser(s),{result:{stdout:`Removing user '${s}' ...
65
+ `,exitCode:0};let s=async(o,a)=>o.trim()!==i?{result:{stderr:`deluser: confirmation did not match \u2014 user not deleted
66
+ `,exitCode:1}}:(await a.users.deleteUser(i),{result:{stdout:`Removing user '${i}' ...
67
67
  deluser: done.
68
- `,exitCode:0}});return{sudoChallenge:{username:s,targetUser:s,commandLine:null,loginShell:!1,prompt:`Warning: deleting user '${s}'.
69
- Type the username to confirm: `,mode:"confirm",onPassword:i},exitCode:0}}};var Lf={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}
70
- ${a}`,exitCode:0}}};var Df={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=he(t,r),o=he(t,s),a,c;try{a=n.vfs.readFile(i).split(`
68
+ `,exitCode:0}});return{sudoChallenge:{username:i,targetUser:i,commandLine:null,loginShell:!1,prompt:`Warning: deleting user '${i}'.
69
+ Type the username to confirm: `,mode:"confirm",onPassword:s},exitCode:0}}};var Uf={name:"df",description:"Report filesystem disk space usage",category:"system",params:["[-h]"],run:({shell:n})=>{let e=(n.vfs.getUsageBytes()/1024).toFixed(0),r="1048576",i=String(Number(r)-Number(e)),s=Math.round(Number(e)/Number(r)*100),o="Filesystem 1K-blocks Used Available Use% Mounted on",a=`virtual-fs ${r.padStart(9)} ${e.padStart(7)} ${i.padStart(9)} ${s}% /`;return{stdout:`${o}
70
+ ${a}`,exitCode:0}}};var $f={name:"diff",description:"Compare files line by line",category:"text",params:["<file1> <file2>"],run:({shell:n,cwd:t,args:e})=>{let[r,i]=e;if(!r||!i)return{stderr:"diff: missing operand",exitCode:1};let s=he(t,r),o=he(t,i),a,c;try{a=n.vfs.readFile(s).split(`
71
71
  `)}catch{return{stderr:`diff: ${r}: No such file or directory`,exitCode:2}}try{c=n.vfs.readFile(o).split(`
72
- `)}catch{return{stderr:`diff: ${s}: No such file or directory`,exitCode:2}}let l=[],u=Math.max(a.length,c.length);for(let f=0;f<u;f++){let h=a[f],p=c[f];h!==p&&(h!==void 0&&l.push(`< ${h}`),p!==void 0&&l.push(`> ${p}`))}return{stdout:l.join(`
73
- `),exitCode:l.length>0?1:0}}};var Uf={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=Yr(e);if(!r)return{stderr:"dpkg: package manager not initialised",exitCode:1};let s=ae(n,["-l","--list"]),i=ae(n,["-s","--status"]),o=ae(n,["-L","--listfiles"]),a=ae(n,["-r","--remove"]),c=ae(n,["-P","--purge"]),{positionals:l}=en(n,{flags:["-l","--list","-s","--status","-L","--listfiles","-r","--remove","-P","--purge"]});if(s){let u=r.listInstalled();if(u.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(`
72
+ `)}catch{return{stderr:`diff: ${i}: No such file or directory`,exitCode:2}}let l=[],u=Math.max(a.length,c.length);for(let f=0;f<u;f++){let h=a[f],p=c[f];h!==p&&(h!==void 0&&l.push(`< ${h}`),p!==void 0&&l.push(`> ${p}`))}return{stdout:l.join(`
73
+ `),exitCode:l.length>0?1:0}}};var Ff={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=jr(e);if(!r)return{stderr:"dpkg: package manager not initialised",exitCode:1};let i=ae(n,["-l","--list"]),s=ae(n,["-s","--status"]),o=ae(n,["-L","--listfiles"]),a=ae(n,["-r","--remove"]),c=ae(n,["-P","--purge"]),{positionals:l}=en(n,{flags:["-l","--list","-s","--status","-L","--listfiles","-r","--remove","-P","--purge"]});if(i){let u=r.listInstalled();if(u.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(`
74
74
  `),exitCode:0};let f=["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=u.map(p=>{let y=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 ${y} ${E} ${S} ${x}`});return{stdout:[...f,...h].join(`
75
- `),exitCode:0}}if(i){let u=l[0];if(!u)return{stderr:"dpkg: -s needs a package name",exitCode:1};let f=r.show(u);return f?{stdout:f,exitCode:0}:{stderr:`dpkg-query: package '${u}' is not installed and no information is available`,exitCode:1}}if(o){let u=l[0];if(!u)return{stderr:"dpkg: -L needs a package name",exitCode:1};let f=r.listInstalled().find(h=>h.name===u);return f?f.files.length===0?{stdout:"/.keep",exitCode:0}:{stdout:f.files.join(`
75
+ `),exitCode:0}}if(s){let u=l[0];if(!u)return{stderr:"dpkg: -s needs a package name",exitCode:1};let f=r.show(u);return f?{stdout:f,exitCode:0}:{stderr:`dpkg-query: package '${u}' is not installed and no information is available`,exitCode:1}}if(o){let u=l[0];if(!u)return{stderr:"dpkg: -L needs a package name",exitCode:1};let f=r.listInstalled().find(h=>h.name===u);return f?f.files.length===0?{stdout:"/.keep",exitCode:0}:{stdout:f.files.join(`
76
76
  `),exitCode:0}:{stderr:`dpkg-query: package '${u}' 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:u,exitCode:f}=r.remove(l,{purge:c});return{stdout:u||void 0,exitCode:f}}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(`
77
- `),exitCode:0}}},$f={name:"dpkg-query",description:"Show information about installed packages",category:"package",params:["-W [pkg] | -l [pattern]"],run:({args:n,shell:t})=>{let e=Yr(t);if(!e)return{stderr:"dpkg-query: package manager not initialised",exitCode:1};let r=ae(n,["-l"]),s=ae(n,["-W","--show"]),{positionals:i}=en(n,{flags:["-l","-W","--show"]});if(r||s){let o=e.listInstalled(),a=i[0],c=a?o.filter(u=>u.name.includes(a)):o;return s?{stdout:c.map(u=>`${u.name} ${u.version}`).join(`
77
+ `),exitCode:0}}},Hf={name:"dpkg-query",description:"Show information about installed packages",category:"package",params:["-W [pkg] | -l [pattern]"],run:({args:n,shell:t})=>{let e=jr(t);if(!e)return{stderr:"dpkg-query: package manager not initialised",exitCode:1};let r=ae(n,["-l"]),i=ae(n,["-W","--show"]),{positionals:s}=en(n,{flags:["-l","-W","--show"]});if(r||i){let o=e.listInstalled(),a=s[0],c=a?o.filter(u=>u.name.includes(a)):o;return i?{stdout:c.map(u=>`${u.name} ${u.version}`).join(`
78
78
  `),exitCode:0}:{stdout:c.map(u=>{let f=u.name.padEnd(14).slice(0,14),h=u.version.padEnd(15).slice(0,15);return`ii ${f} ${h} amd64 ${(u.description||"").slice(0,40)}`}).join(`
79
- `)||"(no packages match)",exitCode:0}}return{stderr:"dpkg-query: need a flag (-l, -W)",exitCode:1}}};var Ff={name:"du",description:"Estimate file space usage",category:"system",params:["[-h] [-s] [path]"],run:({shell:n,cwd:t,args:e})=>{let r=ae(e,["-h"]),s=ae(e,["-s"]),i=e.find(u=>!u.startsWith("-"))??".",o=he(t,i),a=u=>r?`${(u/1024).toFixed(1)}K`:String(Math.ceil(u/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=(u,f)=>{let h=0;for(let p of n.vfs.list(u)){let y=`${u}/${p}`,E=`${f}/${p}`,S=n.vfs.stat(y);S.type==="directory"?h+=l(y,E):(h+=S.size,s||c.push(`${a(S.size)} ${E}`))}return c.push(`${a(h)} ${f}`),h};return l(o,i),{stdout:c.join(`
80
- `),exitCode:0}}};function kA(n){return n.replace(/\\n/g,`
81
- `).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 Hf={name:"echo",description:"Display text",category:"shell",params:["[-n] [-e] [text...]"],run:({args:n,stdin:t,env:e})=>{let{flags:r,positionals:s}=en(n,{flags:["-n","-e","-E"]}),i=r.has("-n"),o=r.has("-e"),a=s.length>0?s.join(" "):t??"",c=qs(a,e?.vars??{},e?.lastExitCode??0),l=o?kA(c):c;return{stdout:i?l:`${l}
82
- `,exitCode:0}}};var Qf={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(`
83
- `),exitCode:0}}};var Wf={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 qf={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(`
79
+ `)||"(no packages match)",exitCode:0}}return{stderr:"dpkg-query: need a flag (-l, -W)",exitCode:1}}};var Qf={name:"du",description:"Estimate file space usage",category:"system",params:["[-h] [-s] [path]"],run:({shell:n,cwd:t,args:e})=>{let r=ae(e,["-h"]),i=ae(e,["-s"]),s=e.find(u=>!u.startsWith("-"))??".",o=he(t,s),a=u=>r?`${(u/1024).toFixed(1)}K`:String(Math.ceil(u/1024));if(!n.vfs.exists(o))return{stderr:`du: ${s}: No such file or directory`,exitCode:1};if(i||n.vfs.stat(o).type==="file")return{stdout:`${a(n.vfs.getUsageBytes(o))} ${s}`,exitCode:0};let c=[],l=(u,f)=>{let h=0;for(let p of n.vfs.list(u)){let y=`${u}/${p}`,E=`${f}/${p}`,S=n.vfs.stat(y);S.type==="directory"?h+=l(y,E):(h+=S.size,i||c.push(`${a(S.size)} ${E}`))}return c.push(`${a(h)} ${f}`),h};return l(o,s),{stdout:c.join(`
80
+ `),exitCode:0}}};function BA(n){return n.replace(/\\n/g,`
81
+ `).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 Wf={name:"echo",description:"Display text",category:"shell",params:["[-n] [-e] [text...]"],run:({args:n,stdin:t,env:e})=>{let{flags:r,positionals:i}=en(n,{flags:["-n","-e","-E"]}),s=r.has("-n"),o=r.has("-e"),a=i.length>0?i.join(" "):t??"",c=Ks(a,e?.vars??{},e?.lastExitCode??0),l=o?BA(c):c;return{stdout:s?l:`${l}
82
+ `,exitCode:0}}};var qf={name:"env",description:"Print environment variables",category:"shell",params:[],run:({env:n,authUser:t})=>{let e={...n.vars,USER:t,HOME:`/home/${t}`};return{stdout:Object.entries(e).map(([r,i])=>`${r}=${i}`).join(`
83
+ `),exitCode:0}}};var Kf={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 Vf={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,i])=>`declare -x ${r}="${i}"`).join(`
84
84
  `);return{stdout:e?`${e}
85
- `:"",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 Kf={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=an(r,["-name"]),i=an(r,["-type"]),a=r.filter(h=>!h.startsWith("-")&&h!==s&&h!==i)[0]??".",c=he(e,a);try{if(Fe(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,u=[],f=(h,p)=>{let y=t.vfs.stat(h),E=!i||i==="f"&&y.type==="file"||i==="d"&&y.type==="directory",S=!l||l.test(h.split("/").pop()??"");if(E&&S&&u.push(p),y.type==="directory")for(let x of t.vfs.list(h)){let P=`${h}/${x}`,q=`${p}/${x}`;f(P,q)}};return f(c,a),{stdout:u.join(`
86
- `),exitCode:0}}};var zs=Yt(require("node:os"),1);var Vf={name:"free",description:"Display amount of free and used memory",category:"system",params:["[-h] [-m] [-g]"],run:({args:n})=>{let t=ae(n,["-h","--human"]),e=ae(n,["-m"]),r=ae(n,["-g"]),s=zs.totalmem(),i=zs.freemem(),o=s-i,a=Math.floor(s*.02),c=Math.floor(s*.05),l=Math.floor(i*.95),u=Math.floor(s*.5),f=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: ${f(s).padStart(12)} ${f(o).padStart(11)} ${f(i).padStart(11)} ${f(a).padStart(11)} ${f(c).padStart(11)} ${f(l).padStart(11)}`,y=`Swap: ${f(u).padStart(12)} ${f(0).padStart(11)} ${f(u).padStart(11)}`;return{stdout:[h,p,y].join(`
87
- `),exitCode:0}}};var zf={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}=en(r,{flags:["-i","-v","-n","-r","-c","-l","-L","-q","--quiet","--silent"]}),a=i.has("-i"),c=i.has("-v"),l=i.has("-n"),u=i.has("-r"),f=i.has("-c"),h=i.has("-l"),p=i.has("-q")||i.has("--quiet")||i.has("--silent"),y=o[0],E=o.slice(1);if(!y)return{stderr:"grep: no pattern specified",exitCode:1};let S;try{let C=a?"mi":"m";S=new RegExp(y,C)}catch{return{stderr:`grep: invalid regex: ${y}`,exitCode:1}}let x=(C,$="")=>{let F=C.split(`
88
- `),v=[];for(let b=0;b<F.length;b++){let w=F[b]??"",k=S.test(w);if(c?!k:k){let R=l?`${b+1}:`:"";v.push(`${$}${R}${w}`)}}return v},P=C=>{if(!t.vfs.exists(C))return[];if(t.vfs.stat(C).type==="file")return[C];if(!u)return[];let F=[],v=b=>{for(let w of t.vfs.list(b)){let k=`${b}/${w}`;t.vfs.stat(k).type==="file"?F.push(k):v(k)}};return v(C),F},q=[];if(E.length===0){if(!s)return{stdout:"",exitCode:1};let C=x(s);if(f)return{stdout:`${C.length}
85
+ `:"",exitCode:0}}for(let e of n.filter(r=>r!=="-p"))if(e.includes("=")){let r=e.indexOf("="),i=e.slice(0,r),s=e.slice(r+1);t.vars[i]=s}return{exitCode:0}}};var zf={name:"find",description:"Search for files",category:"files",params:["[path] [-name <pattern>] [-type f|d]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=an(r,["-name"]),s=an(r,["-type"]),a=r.filter(h=>!h.startsWith("-")&&h!==i&&h!==s)[0]??".",c=he(e,a);try{if(Fe(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=i?new RegExp(`^${i.replace(/\./g,"\\.").replace(/\*/g,".*").replace(/\?/g,".")}$`):null,u=[],f=(h,p)=>{let y=t.vfs.stat(h),E=!s||s==="f"&&y.type==="file"||s==="d"&&y.type==="directory",S=!l||l.test(h.split("/").pop()??"");if(E&&S&&u.push(p),y.type==="directory")for(let x of t.vfs.list(h)){let P=`${h}/${x}`,q=`${p}/${x}`;f(P,q)}};return f(c,a),{stdout:u.join(`
86
+ `),exitCode:0}}};var Ys=Yt(require("node:os"),1);var Gf={name:"free",description:"Display amount of free and used memory",category:"system",params:["[-h] [-m] [-g]"],run:({args:n})=>{let t=ae(n,["-h","--human"]),e=ae(n,["-m"]),r=ae(n,["-g"]),i=Ys.totalmem(),s=Ys.freemem(),o=i-s,a=Math.floor(i*.02),c=Math.floor(i*.05),l=Math.floor(s*.95),u=Math.floor(i*.5),f=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: ${f(i).padStart(12)} ${f(o).padStart(11)} ${f(s).padStart(11)} ${f(a).padStart(11)} ${f(c).padStart(11)} ${f(l).padStart(11)}`,y=`Swap: ${f(u).padStart(12)} ${f(0).padStart(11)} ${f(u).padStart(11)}`;return{stdout:[h,p,y].join(`
87
+ `),exitCode:0}}};var Yf={name:"grep",description:"Search text patterns",category:"text",params:["[-i] [-v] [-n] [-r] <pattern> [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let{flags:s,positionals:o}=en(r,{flags:["-i","-v","-n","-r","-c","-l","-L","-q","--quiet","--silent"]}),a=s.has("-i"),c=s.has("-v"),l=s.has("-n"),u=s.has("-r"),f=s.has("-c"),h=s.has("-l"),p=s.has("-q")||s.has("--quiet")||s.has("--silent"),y=o[0],E=o.slice(1);if(!y)return{stderr:"grep: no pattern specified",exitCode:1};let S;try{let C=a?"mi":"m";S=new RegExp(y,C)}catch{return{stderr:`grep: invalid regex: ${y}`,exitCode:1}}let x=(C,$="")=>{let F=C.split(`
88
+ `),v=[];for(let b=0;b<F.length;b++){let w=F[b]??"",k=S.test(w);if(c?!k:k){let R=l?`${b+1}:`:"";v.push(`${$}${R}${w}`)}}return v},P=C=>{if(!t.vfs.exists(C))return[];if(t.vfs.stat(C).type==="file")return[C];if(!u)return[];let F=[],v=b=>{for(let w of t.vfs.list(b)){let k=`${b}/${w}`;t.vfs.stat(k).type==="file"?F.push(k):v(k)}};return v(C),F},q=[];if(E.length===0){if(!i)return{stdout:"",exitCode:1};let C=x(i);if(f)return{stdout:`${C.length}
89
89
  `,exitCode:C.length>0?0:1};if(p)return{exitCode:C.length>0?0:1};q.push(...C)}else{let C=E.flatMap($=>{let F=he(e,$);return P(F).map(v=>({file:$,path:v}))});for(let{file:$,path:F}of C)try{Fe(n,F,"grep");let v=t.vfs.readFile(F),b=C.length>1?`${$}:`:"",w=x(v,b);f?q.push(C.length>1?`${$}:${w.length}`:String(w.length)):h?w.length>0&&q.push($):q.push(...w)}catch{return{stderr:`grep: ${$}: No such file or directory`,exitCode:1}}}return{stdout:q.length>0?`${q.join(`
90
90
  `)}
91
- `:"",exitCode:q.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 Yf={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
91
+ `:"",exitCode:q.length>0?0:1}}};var jf={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 Xf={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
92
92
  Hint: install it with: apt install gzip
93
- `,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
94
- `,exitCode:1};let o=he(t,i);if(s){if(!i.endsWith(".gz"))return{stderr:`gzip: ${i}: unknown suffix -- ignored
95
- `,exitCode:1};if(!n.vfs.exists(o))return{stderr:`gzip: ${i}: No such file or directory
96
- `,exitCode:1};let l=n.vfs.readFile(o),u=o.slice(0,-3);return n.vfs.writeFile(u,l),r||n.vfs.remove(o),{exitCode:0}}if(!n.vfs.exists(o))return{stderr:`gzip: ${i}: No such file or directory
97
- `,exitCode:1};if(i.endsWith(".gz"))return{stderr:`gzip: ${i}: already has .gz suffix -- unchanged
98
- `,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}}},jf={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
99
- `,exitCode:1};let i=he(t,s);if(!n.vfs.exists(i))return{stderr:`gunzip: ${s}: No such file or directory
100
- `,exitCode:1};if(!s.endsWith(".gz"))return{stderr:`gunzip: ${s}: unknown suffix -- ignored
101
- `,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 Xf={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=an(r,["-n"]),o=r.find(f=>/^-\d+$/.test(f)),a=typeof i=="string"?parseInt(i,10):o?parseInt(o.slice(1),10):10,c=r.filter(f=>!f.startsWith("-")&&f!==i&&f!==String(a)),l=f=>{let h=f.split(`
93
+ `,exitCode:127};let r=e.includes("-k")||e.includes("--keep"),i=e.includes("-d"),s=e.find(l=>!l.startsWith("-"));if(!s)return{stderr:`gzip: no file specified
94
+ `,exitCode:1};let o=he(t,s);if(i){if(!s.endsWith(".gz"))return{stderr:`gzip: ${s}: unknown suffix -- ignored
95
+ `,exitCode:1};if(!n.vfs.exists(o))return{stderr:`gzip: ${s}: No such file or directory
96
+ `,exitCode:1};let l=n.vfs.readFile(o),u=o.slice(0,-3);return n.vfs.writeFile(u,l),r||n.vfs.remove(o),{exitCode:0}}if(!n.vfs.exists(o))return{stderr:`gzip: ${s}: No such file or directory
97
+ `,exitCode:1};if(s.endsWith(".gz"))return{stderr:`gzip: ${s}: already has .gz suffix -- unchanged
98
+ `,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}}},Jf={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"),i=e.find(c=>!c.startsWith("-"));if(!i)return{stderr:`gunzip: no file specified
99
+ `,exitCode:1};let s=he(t,i);if(!n.vfs.exists(s))return{stderr:`gunzip: ${i}: No such file or directory
100
+ `,exitCode:1};if(!i.endsWith(".gz"))return{stderr:`gunzip: ${i}: unknown suffix -- ignored
101
+ `,exitCode:1};let o=n.vfs.readFile(s),a=s.slice(0,-3);return n.vfs.writeFile(a,o),r||n.vfs.remove(s),{exitCode:0}}};var Zf={name:"head",description:"Output first lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=an(r,["-n"]),o=r.find(f=>/^-\d+$/.test(f)),a=typeof s=="string"?parseInt(s,10):o?parseInt(o.slice(1),10):10,c=r.filter(f=>!f.startsWith("-")&&f!==s&&f!==String(a)),l=f=>{let h=f.split(`
102
102
  `),p=h.slice(0,a);return p.join(`
103
103
  `)+(f.endsWith(`
104
104
  `)&&p.length===h.slice(0,a).length?`
105
- `:"")};if(c.length===0)return{stdout:l(s??""),exitCode:0};let u=[];for(let f of c){let h=he(e,f);try{Fe(n,h,"head"),u.push(l(t.vfs.readFile(h)))}catch{return{stderr:`head: ${f}: No such file or directory`,exitCode:1}}}return{stdout:u.join(`
106
- `),exitCode:0}}};var Jf=["navigation","files","text","archive","system","package","network","shell","users","misc"],ed={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"},td="\x1B[1m",Bn="\x1B[0m",vA="\x1B[36m",NA="\x1B[33m",Ui="\x1B[2m",BA="\x1B[32m";function Zf(n,t){return n.length>=t?n:n+" ".repeat(t-n.length)}function RA(n){let t=n.aliases?.length?` ${Ui}(${n.aliases.join(", ")})${Bn}`:"";return` ${vA}${Zf(n.name,16)}${Bn}${t}${Zf("",(n.aliases?.length,0))} ${n.description??""}`}function PA(n){let t={};for(let i of n){let o=i.category??"misc";t[o]||(t[o]=[]),t[o].push(i)}let e=[`${td}Available commands${Bn}`,`${Ui}Type 'help <command>' for detailed usage.${Bn}`,""],r=[...Jf.filter(i=>t[i]),...Object.keys(t).filter(i=>!Jf.includes(i)).sort()];for(let i of r){let o=t[i];if(!o?.length)continue;e.push(`${NA}${ed[i]??i}${Bn}`);let a=[...o].sort((c,l)=>c.name.localeCompare(l.name));for(let c of a)e.push(RA(c));e.push("")}let s=n.length;return e.push(`${Ui}${s} commands available.${Bn}`),e.join(`
107
- `)}function TA(n){let t=[];if(t.push(`${td}${n.name}${Bn} \u2014 ${n.description??"no description"}`),n.aliases?.length&&t.push(`${Ui}Aliases: ${n.aliases.join(", ")}${Bn}`),t.push(""),t.push(`${BA}Usage:${Bn}`),n.params.length)for(let r of n.params)t.push(` ${n.name} ${r}`);else t.push(` ${n.name}`);let e=ed[n.category??"misc"]??n.category??"misc";return t.push(""),t.push(`${Ui}Category: ${e}${Bn}`),t.join(`
108
- `)}function nd(n){return{name:"help",description:"List all commands, or show usage for a specific command",category:"shell",params:["[command]"],run:({args:t})=>{let e=lc();if(t[0]){let r=t[0].toLowerCase(),s=e.find(i=>i.name===r||i.aliases?.includes(r));return s?{stdout:TA(s),exitCode:0}:{stderr:`help: no help entry for '${t[0]}'`,exitCode:1}}return{stdout:PA(e),exitCode:0}}}}var rd={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(`
109
- `).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((f,h)=>`${String(l+h).padStart(5)} ${f}`).join(`
110
- `),exitCode:0}}};var id={name:"hostname",description:"Print hostname",category:"system",params:[],run:({hostname:n})=>({stdout:n,exitCode:0})};var sd={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 od={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 ad={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 cd={name:"ln",description:"Create links",category:"files",params:["[-s] <target> <link_name>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=ae(r,["-s","--symbolic"]),i=r.filter(u=>!u.startsWith("-")),[o,a]=i;if(!o||!a)return{stderr:"ln: missing operand",exitCode:1};let c=he(e,a),l=s?o:he(e,o);try{if(Fe(n,c,"ln"),s)t.vfs.symlink(l,c);else{let u=he(e,o);if(Fe(n,u,"ln"),!t.vfs.exists(u))return{stderr:`ln: ${o}: No such file or directory`,exitCode:1};let f=t.vfs.readFile(u);t.writeFileAsUser(n,c,f)}return{exitCode:0}}catch(u){return{stderr:`ln: ${u instanceof Error?u.message:String(u)}`,exitCode:1}}}},ld={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
111
- `,exitCode:1};let i=he(t,s);return n.vfs.exists(i)?n.vfs.isSymlink(i)?{stdout:`${n.vfs.resolveSymlink(i)}
112
- `,exitCode:0}:{stderr:`readlink: ${s}: not a symbolic link
113
- `,exitCode:1}:{stderr:`readlink: ${s}: No such file or directory
114
- `,exitCode:1}}};var ud={name:"seq",description:"Print a sequence of numbers",category:"text",params:["[FIRST [INCREMENT]] LAST"],run:({args:n})=>{let t=n.filter(f=>!f.startsWith("-")||/^-[\d.]/.test(f)).map(Number),e=(()=>{let f=n.indexOf("-s");return f!==-1?n[f+1]??`
105
+ `:"")};if(c.length===0)return{stdout:l(i??""),exitCode:0};let u=[];for(let f of c){let h=he(e,f);try{Fe(n,h,"head"),u.push(l(t.vfs.readFile(h)))}catch{return{stderr:`head: ${f}: No such file or directory`,exitCode:1}}}return{stdout:u.join(`
106
+ `),exitCode:0}}};var ed=["navigation","files","text","archive","system","package","network","shell","users","misc"],nd={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"},rd="\x1B[1m",Bn="\x1B[0m",RA="\x1B[36m",PA="\x1B[33m",$i="\x1B[2m",TA="\x1B[32m";function td(n,t){return n.length>=t?n:n+" ".repeat(t-n.length)}function OA(n){let t=n.aliases?.length?` ${$i}(${n.aliases.join(", ")})${Bn}`:"";return` ${RA}${td(n.name,16)}${Bn}${t}${td("",(n.aliases?.length,0))} ${n.description??""}`}function MA(n){let t={};for(let s of n){let o=s.category??"misc";t[o]||(t[o]=[]),t[o].push(s)}let e=[`${rd}Available commands${Bn}`,`${$i}Type 'help <command>' for detailed usage.${Bn}`,""],r=[...ed.filter(s=>t[s]),...Object.keys(t).filter(s=>!ed.includes(s)).sort()];for(let s of r){let o=t[s];if(!o?.length)continue;e.push(`${PA}${nd[s]??s}${Bn}`);let a=[...o].sort((c,l)=>c.name.localeCompare(l.name));for(let c of a)e.push(OA(c));e.push("")}let i=n.length;return e.push(`${$i}${i} commands available.${Bn}`),e.join(`
107
+ `)}function LA(n){let t=[];if(t.push(`${rd}${n.name}${Bn} \u2014 ${n.description??"no description"}`),n.aliases?.length&&t.push(`${$i}Aliases: ${n.aliases.join(", ")}${Bn}`),t.push(""),t.push(`${TA}Usage:${Bn}`),n.params.length)for(let r of n.params)t.push(` ${n.name} ${r}`);else t.push(` ${n.name}`);let e=nd[n.category??"misc"]??n.category??"misc";return t.push(""),t.push(`${$i}Category: ${e}${Bn}`),t.join(`
108
+ `)}function id(n){return{name:"help",description:"List all commands, or show usage for a specific command",category:"shell",params:["[command]"],run:({args:t})=>{let e=fc();if(t[0]){let r=t[0].toLowerCase(),i=e.find(s=>s.name===r||s.aliases?.includes(r));return i?{stdout:LA(i),exitCode:0}:{stderr:`help: no help entry for '${t[0]}'`,exitCode:1}}return{stdout:MA(e),exitCode:0}}}}var sd={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 s=t.vfs.readFile(r).split(`
109
+ `).filter(Boolean),o=n[0],a=o?parseInt(o,10):null,c=a&&!Number.isNaN(a)?s.slice(-a):s,l=s.length-c.length+1;return{stdout:c.map((f,h)=>`${String(l+h).padStart(5)} ${f}`).join(`
110
+ `),exitCode:0}}};var od={name:"hostname",description:"Print hostname",category:"system",params:[],run:({hostname:n})=>({stdout:n,exitCode:0})};var ad={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 cd={name:"id",description:"Print user identity",category:"system",params:["[user]"],run:({authUser:n,shell:t,args:e})=>{let r=e[0]??n,i=r==="root"?0:1e3,s=i,a=t.users.isSudoer(r)?`${s}(${r}),0(root)`:`${s}(${r})`;return{stdout:`uid=${i}(${r}) gid=${s}(${r}) groups=${a}`,exitCode:0}}};var ld={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 ud={name:"ln",description:"Create links",category:"files",params:["[-s] <target> <link_name>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=ae(r,["-s","--symbolic"]),s=r.filter(u=>!u.startsWith("-")),[o,a]=s;if(!o||!a)return{stderr:"ln: missing operand",exitCode:1};let c=he(e,a),l=i?o:he(e,o);try{if(Fe(n,c,"ln"),i)t.vfs.symlink(l,c);else{let u=he(e,o);if(Fe(n,u,"ln"),!t.vfs.exists(u))return{stderr:`ln: ${o}: No such file or directory`,exitCode:1};let f=t.vfs.readFile(u);t.writeFileAsUser(n,c,f)}return{exitCode:0}}catch(u){return{stderr:`ln: ${u instanceof Error?u.message:String(u)}`,exitCode:1}}}},fd={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"),i=e.find(a=>!a.startsWith("-"));if(!i)return{stderr:`readlink: missing operand
111
+ `,exitCode:1};let s=he(t,i);return n.vfs.exists(s)?n.vfs.isSymlink(s)?{stdout:`${n.vfs.resolveSymlink(s)}
112
+ `,exitCode:0}:{stderr:`readlink: ${i}: not a symbolic link
113
+ `,exitCode:1}:{stderr:`readlink: ${i}: No such file or directory
114
+ `,exitCode:1}}};var dd={name:"seq",description:"Print a sequence of numbers",category:"text",params:["[FIRST [INCREMENT]] LAST"],run:({args:n})=>{let t=n.filter(f=>!f.startsWith("-")||/^-[\d.]/.test(f)).map(Number),e=(()=>{let f=n.indexOf("-s");return f!==-1?n[f+1]??`
115
115
  `:`
116
- `})(),r=(()=>{let f=n.indexOf("-f");return f!==-1?n[f+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
117
- `,exitCode:1};if(o>0&&i>a||o<0&&i<a)return{stdout:"",exitCode:0};let c=[],l=1e5,u=0;for(let f=i;(o>0?f<=a:f>=a)&&!(++u>l);f=Math.round((f+o)*1e10)/1e10){let h;if(r?h=r.replace("%g",String(f)).replace("%f",f.toFixed(6)).replace("%d",String(Math.trunc(f))):h=Number.isInteger(f)?String(f):f.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)}
118
- `,exitCode:0}}};var fd={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
119
- `,exitCode:1};let o=he(t,i);if(!n.vfs.exists(o))return{stderr:`stat: cannot stat '${i}': No such file or directory
120
- `,exitCode:1};let a=n.vfs.stat(o),c=a.type==="directory",l=n.vfs.isSymlink(o),u=n.vfs.isSymlink(o),f=x=>{let P=[256,128,64,32,16,8,4,2,1],q=["r","w","x","r","w","x","r","w","x"];return(c?"d":u?"l":"-")+P.map((C,$)=>x&C?q[$]:"-").join("")},h=a.mode.toString(8).padStart(4,"0"),p=f(a.mode),y="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(y)).replace("%a",h.slice(1)).replace("%A",p).replace("%F",u?"symbolic link":c?"directory":"regular file").replace("%y",E(a.updatedAt)).replace("%z",E(a.updatedAt))}
121
- `,exitCode:0}:{stdout:`${[` File: ${i}${u?` -> ${n.vfs.resolveSymlink(o)}`:""}`,` Size: ${y}${" ".repeat(3)}${u?"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
+ `})(),r=(()=>{let f=n.indexOf("-f");return f!==-1?n[f+1]??"%g":null})(),i=n.includes("-w"),s=1,o=1,a;if(t.length===1?a=t[0]:t.length===2?(s=t[0],a=t[1]):(s=t[0],o=t[1],a=t[2]),o===0)return{stderr:`seq: zero increment
117
+ `,exitCode:1};if(o>0&&s>a||o<0&&s<a)return{stdout:"",exitCode:0};let c=[],l=1e5,u=0;for(let f=s;(o>0?f<=a:f>=a)&&!(++u>l);f=Math.round((f+o)*1e10)/1e10){let h;if(r?h=r.replace("%g",String(f)).replace("%f",f.toFixed(6)).replace("%d",String(Math.trunc(f))):h=Number.isInteger(f)?String(f):f.toPrecision(12).replace(/\.?0+$/,""),i){let p=String(Math.trunc(a)).length;h=h.padStart(p,"0")}c.push(h)}return{stdout:`${c.join(e)}
118
+ `,exitCode:0}}};var hd={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"),i=r!==-1?e[r+1]:void 0,s=e.find(x=>!x.startsWith("-")&&x!==i);if(!s)return{stderr:`stat: missing operand
119
+ `,exitCode:1};let o=he(t,s);if(!n.vfs.exists(o))return{stderr:`stat: cannot stat '${s}': No such file or directory
120
+ `,exitCode:1};let a=n.vfs.stat(o),c=a.type==="directory",l=n.vfs.isSymlink(o),u=n.vfs.isSymlink(o),f=x=>{let P=[256,128,64,32,16,8,4,2,1],q=["r","w","x","r","w","x","r","w","x"];return(c?"d":u?"l":"-")+P.map((C,$)=>x&C?q[$]:"-").join("")},h=a.mode.toString(8).padStart(4,"0"),p=f(a.mode),y="size"in a?a.size:0,E=x=>x.toISOString().replace("T"," ").replace(/\.\d+Z$/," +0000");return i?{stdout:`${i.replace("%n",s).replace("%s",String(y)).replace("%a",h.slice(1)).replace("%A",p).replace("%F",u?"symbolic link":c?"directory":"regular file").replace("%y",E(a.updatedAt)).replace("%z",E(a.updatedAt))}
121
+ `,exitCode:0}:{stdout:`${[` File: ${s}${u?` -> ${n.vfs.resolveSymlink(o)}`:""}`,` Size: ${y}${" ".repeat(3)}${u?"symbolic link":c?"directory":"regular file"}`,`Access: (${h}/${p}) Uid: ( 0/ root) Gid: ( 0/ root)`,`Modify: ${E(a.updatedAt)}`,`Change: ${E(a.updatedAt)}`].join(`
122
122
  `)}
123
- `,exitCode:0}}};var OA="\x1B[0m",MA="\x1B[1;34m",LA="\x1B[1;36m",DA="\x1B[1;32m",UA="",$A="\x1B[30;42m",FA="\x1B[37;44m",HA="\x1B[34;42m";function Jr(n,t){return t?`${t}${n}${OA}`:n}function dc(n,t,e){if(e)return LA;if(t==="directory"){let r=!!(n&512),s=!!(n&2);return r&&s?$A:r?FA:s?HA:MA}return n&73?DA:UA}function dd(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 QA=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function fc(n){let t=new Date,e=4320*3600*1e3,r=Math.abs(t.getTime()-n.getTime())<e,s=String(n.getDate()).padStart(2," "),i=QA[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 Gs(n,t){try{return n.readFile(t)}catch{return"?"}}function WA(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=dc(a.mode,a.type,o);return Jr(s,c)}).join(" ")}function qA(n,t,e){let r=t==="/"?"":t,s=e.map(f=>{let h=`${r}/${f}`,p=n.isSymlink(h),y;try{y=n.stat(h)}catch{return{perms:"----------",nlink:"1",size:"0",date:fc(new Date),label:f}}let E=p?41471:y.mode,S=dd(E,y.type,p),x=y.type==="directory"?String((y.childrenCount??0)+2):"1",P=p?Gs(n,h).length:y.type==="file"?y.size??0:(y.childrenCount??0)*4096,q=String(P),C=fc(y.updatedAt),$=dc(E,y.type,p),F=p?`${Jr(f,$)} -> ${Gs(n,h)}`:Jr(f,$);return{perms:S,nlink:x,size:q,date:C,label:F}}),i=Math.max(...s.map(f=>f.nlink.length)),o=Math.max(...s.map(f=>f.size.length)),a="root",c="root",l=e.length*8,u=s.map(f=>`${f.perms} ${f.nlink.padStart(i)} ${a} ${c} ${f.size.padStart(o)} ${f.date} ${f.label}`);return`total ${l}
123
+ `,exitCode:0}}};var DA="\x1B[0m",UA="\x1B[1;34m",$A="\x1B[1;36m",FA="\x1B[1;32m",HA="",QA="\x1B[30;42m",WA="\x1B[37;44m",qA="\x1B[34;42m";function Zr(n,t){return t?`${t}${n}${DA}`:n}function pc(n,t,e){if(e)return $A;if(t==="directory"){let r=!!(n&512),i=!!(n&2);return r&&i?QA:r?WA:i?qA:UA}return n&73?FA:HA}function pd(n,t,e){let r;e?r="l":t==="directory"?r="d":r="-";let i=l=>n&l?"r":"-",s=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}${i(256)}${s(128)}${o}${i(32)}${s(16)}${a}${i(4)}${s(2)}${c}`}var KA=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function hc(n){let t=new Date,e=4320*3600*1e3,r=Math.abs(t.getTime()-n.getTime())<e,i=String(n.getDate()).padStart(2," "),s=KA[n.getMonth()]??"";if(r){let o=String(n.getHours()).padStart(2,"0"),a=String(n.getMinutes()).padStart(2,"0");return`${i} ${s.padEnd(3)} ${o}:${a}`}return`${i} ${s.padEnd(3)} ${n.getFullYear()}`}function js(n,t){try{return n.readFile(t)}catch{return"?"}}function VA(n,t,e){let r=t==="/"?"":t;return e.map(i=>{let s=`${r}/${i}`,o=n.isSymlink(s),a;try{a=n.stat(s)}catch{return i}let c=pc(a.mode,a.type,o);return Zr(i,c)}).join(" ")}function zA(n,t,e){let r=t==="/"?"":t,i=e.map(f=>{let h=`${r}/${f}`,p=n.isSymlink(h),y;try{y=n.stat(h)}catch{return{perms:"----------",nlink:"1",size:"0",date:hc(new Date),label:f}}let E=p?41471:y.mode,S=pd(E,y.type,p),x=y.type==="directory"?String((y.childrenCount??0)+2):"1",P=p?js(n,h).length:y.type==="file"?y.size??0:(y.childrenCount??0)*4096,q=String(P),C=hc(y.updatedAt),$=pc(E,y.type,p),F=p?`${Zr(f,$)} -> ${js(n,h)}`:Zr(f,$);return{perms:S,nlink:x,size:q,date:C,label:F}}),s=Math.max(...i.map(f=>f.nlink.length)),o=Math.max(...i.map(f=>f.size.length)),a="root",c="root",l=e.length*8,u=i.map(f=>`${f.perms} ${f.nlink.padStart(s)} ${a} ${c} ${f.size.padStart(o)} ${f.date} ${f.label}`);return`total ${l}
124
124
  ${u.join(`
125
- `)}`}var hd={name:"ls",description:"List directory contents",category:"navigation",params:["[-la] [path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=ae(r,["-l","--long","-la","-al"]),i=ae(r,["-a","--all","-la","-al"]),o=rr(r,0,{flags:["-l","--long","-a","--all","-la","-al"]}),a=he(e,o??e);if(Fe(n,a,"ls"),t.vfs.exists(a)){let u=t.vfs.stat(a),f=t.vfs.isSymlink(a);if(u.type==="file"||f){let h=a.split("/").pop()??a,p=dc(f?41471:u.mode,u.type,f);if(s){let y=f?41471:u.mode,E=f?Gs(t.vfs,a).length:u.size??0,S=dd(y,u.type,f),x=f?`${Jr(h,p)} -> ${Gs(t.vfs,a)}`:Jr(h,p);return{stdout:`${S} 1 root root ${E} ${fc(u.updatedAt)} ${x}
126
- `,exitCode:0}}return{stdout:`${Jr(h,p)}
127
- `,exitCode:0}}}let c=t.vfs.list(a).filter(u=>i||!u.startsWith("."));return{stdout:`${s?qA(t.vfs,a,c):WA(t.vfs,a,c)}
128
- `,exitCode:0}}};var pd={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="nyx",s="1.0";try{let f=t.vfs.readFile("/etc/os-release");for(let h of f.split(`
129
- `))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=ae(n,["-a","--all"]),o=ae(n,["-i","--id"]),a=ae(n,["-d","--description"]),c=ae(n,["-r","--release"]),l=ae(n,["-c","--codename"]);if(i||n.length===0)return{stdout:["Distributor ID: Fortune",`Description: ${e}`,`Release: ${s}`,`Codename: ${r}`].join(`
130
- `),exitCode:0};let u=[];return o&&u.push("Distributor ID: Fortune"),a&&u.push(`Description: ${e}`),c&&u.push(`Release: ${s}`),l&&u.push(`Codename: ${r}`),{stdout:u.join(`
131
- `),exitCode:0}}};var md={adduser:`ADDUSER(8) User Commands ADDUSER(8)
125
+ `)}`}var md={name:"ls",description:"List directory contents",category:"navigation",params:["[-la] [path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=ae(r,["-l","--long","-la","-al"]),s=ae(r,["-a","--all","-la","-al"]),o=rr(r,0,{flags:["-l","--long","-a","--all","-la","-al"]}),a=he(e,o??e);if(Fe(n,a,"ls"),t.vfs.exists(a)){let u=t.vfs.stat(a),f=t.vfs.isSymlink(a);if(u.type==="file"||f){let h=a.split("/").pop()??a,p=pc(f?41471:u.mode,u.type,f);if(i){let y=f?41471:u.mode,E=f?js(t.vfs,a).length:u.size??0,S=pd(y,u.type,f),x=f?`${Zr(h,p)} -> ${js(t.vfs,a)}`:Zr(h,p);return{stdout:`${S} 1 root root ${E} ${hc(u.updatedAt)} ${x}
126
+ `,exitCode:0}}return{stdout:`${Zr(h,p)}
127
+ `,exitCode:0}}}let c=t.vfs.list(a).filter(u=>s||!u.startsWith("."));return{stdout:`${i?zA(t.vfs,a,c):VA(t.vfs,a,c)}
128
+ `,exitCode:0}}};var gd={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="nyx",i="1.0";try{let f=t.vfs.readFile("/etc/os-release");for(let h of f.split(`
129
+ `))h.startsWith("PRETTY_NAME=")&&(e=h.slice(12).replace(/^"|"$/g,"").trim()),h.startsWith("VERSION_CODENAME=")&&(r=h.slice(17).trim()),h.startsWith("VERSION_ID=")&&(i=h.slice(11).replace(/^"|"$/g,"").trim())}catch{}let s=ae(n,["-a","--all"]),o=ae(n,["-i","--id"]),a=ae(n,["-d","--description"]),c=ae(n,["-r","--release"]),l=ae(n,["-c","--codename"]);if(s||n.length===0)return{stdout:["Distributor ID: Fortune",`Description: ${e}`,`Release: ${i}`,`Codename: ${r}`].join(`
130
+ `),exitCode:0};let u=[];return o&&u.push("Distributor ID: Fortune"),a&&u.push(`Description: ${e}`),c&&u.push(`Release: ${i}`),l&&u.push(`Codename: ${r}`),{stdout:u.join(`
131
+ `),exitCode:0}}};var Ad={adduser:`ADDUSER(8) User Commands ADDUSER(8)
132
132
 
133
133
  NAME
134
134
  adduser - add a user to the system
@@ -938,113 +938,113 @@ SYNOPSIS
938
938
  xargs [COMMAND [INITIAL-ARGS]]
939
939
 
940
940
  DESCRIPTION
941
- Read items from stdin and execute COMMAND with those items as arguments.`};var KA={gunzip:"gzip"},gd={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=e.toLowerCase(),i=KA[s]??s,o=md[i]??null;return o?{stdout:o,exitCode:0}:{stderr:`No manual entry for ${e}`,exitCode:16}}};var Ad={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=rr(r,s);if(!i)return{stderr:"mkdir: missing operand",exitCode:1};let o=he(e,i);Fe(n,o,"mkdir"),t.vfs.mkdir(o)}return{exitCode:0}}};var yd={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=he(e,i),c=he(e,o);try{if(Fe(n,a,"mv"),Fe(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 Ed=Yt(require("node:path"),1);var _d={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=he(e,s);Fe(n,i,"nano");let o=t.vfs.exists(i)?t.vfs.readFile(i):"",a=Ed.posix.basename(i)||"buffer",c=`/tmp/sshmimic-nano-${Date.now()}-${a}.tmp`;return{openEditor:{targetPath:i,tempPath:c,initialContent:o},exitCode:0}}};var Wn=require("node:fs"),Wt=Yt(require("node:os"),1),kd=Yt(require("node:path"),1);function VA(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 bd(n){return`\x1B[${n}m \x1B[0m`}function zA(){let n=[40,41,42,43,44,45,46,47].map(bd).join(""),t=[100,101,102,103,104,105,106,107].map(bd).join("");return[n,t]}function Sd(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 GA(n){if(n.trim().length===0)return n;let t=n.indexOf(":");if(t===-1)return n.includes("@")?xd(n):n;let e=n.substring(0,t+1),r=n.substring(t+1);return xd(e)+r}function xd(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),u=Math.round(r.b+(s.b-r.b)*a);i+=`\x1B[38;2;${c};${l};${u}m${e[o]}\x1B[0m`}return i}function wd(n){return Math.max(0,Math.round(n/(1024*1024)))}function Id(){try{let n=(0,Wn.readFileSync)("/etc/os-release","utf8");for(let t of n.split(`
942
- `)){if(!t.startsWith("PRETTY_NAME="))continue;return t.slice(12).trim().replace(/^"|"$/g,"")}}catch{return}}function Cd(n){try{let t=(0,Wn.readFileSync)(n,"utf8").split(`
943
- `)[0]?.trim();return!t||t.length===0?void 0:t}catch{return}}function YA(n){let t=Cd("/sys/devices/virtual/dmi/id/sys_vendor"),e=Cd("/sys/devices/virtual/dmi/id/product_name");return t&&e?`${t} ${e}`:e||n}function jA(){let n=["/var/lib/dpkg/status","/usr/local/var/lib/dpkg/status"];for(let t of n)if((0,Wn.existsSync)(t))try{return(0,Wn.readFileSync)(t,"utf8").match(/^Package:\s+/gm)?.length??0}catch{}}function XA(){let n=["/snap","/var/lib/snapd/snaps"];for(let t of n)if((0,Wn.existsSync)(t))try{return(0,Wn.readdirSync)(t,{withFileTypes:!0}).filter(s=>s.isDirectory()).length}catch{}}function JA(){let n=jA(),t=XA();return n!==void 0&&t!==void 0?`${n} (dpkg), ${t} (snap)`:n!==void 0?`${n} (dpkg)`:t!==void 0?`${t} (snap)`:"n/a"}function ZA(){let n=Wt.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 ey(n){return!n||n.trim().length===0?"unknown":kd.posix.basename(n.trim())}function ty(n){let t=Wt.totalmem(),e=Wt.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??`${Id()??Wt.type()} ${Wt.arch()}`,kernel:s?.kernel??n.kernel??Wt.release(),uptimeSeconds:n.uptimeSeconds??Wt.uptime(),packages:n.packages??JA(),shell:ey(n.shell),shellProps:n.shellProps??{kernel:n.kernel??Wt.release(),os:n.osName??`${Id()??Wt.type()} ${Wt.arch()}`,arch:Wt.arch()},resolution:n.resolution??"n/a (ssh)",terminal:n.terminal??"unknown",cpu:n.cpu??ZA(),gpu:n.gpu??"n/a",memoryUsedMiB:n.memoryUsedMiB??wd(r),memoryTotalMiB:n.memoryTotalMiB??wd(t)}}function vd(n){let t=ty(n),e=VA(t.uptimeSeconds),r=zA(),s=[" .. .:. "," .::.. .. .. ",". .... ... .. ",": .... .:. .. ",": .:.:........:. .. ",": .. ",". : ",". : ",".. : "," :. .. "," .. .. "," :-. :: "," .:. :. "," ..: ... "," ..: :.. "," :... :...."," .. ...."," . .. "," .:. .: "," :. .. "," ::. .. ","..... ..:... ","...:. .. ",".:...:. ::. .. "," ... ..:::::.. ..:::::::.. "],i=[`${t.user}@${t.host}`,"-------------------------",`OS: ${t.osName}`,`Host: ${YA(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]??"",u=i[c]??"";if(u.length>0){let f=Sd(l.padEnd(31," "),c,s.length),h=GA(u);a.push(`${f} ${h}`);continue}a.push(Sd(l,c,s.length))}return a.join(`
944
- `)}var Nd={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")?ae(n,"--help")?{stdout:"Usage: neofetch [--off]",exitCode:0}:ae(n,"--off")?{stdout:`${t}@${e}`,exitCode:0}:{stdout:vd({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
941
+ Read items from stdin and execute COMMAND with those items as arguments.`};var GA={gunzip:"gzip"},yd={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 i=e.toLowerCase(),s=GA[i]??i,o=Ad[s]??null;return o?{stdout:o,exitCode:0}:{stderr:`No manual entry for ${e}`,exitCode:16}}};var Ed={name:"mkdir",description:"Make directories",category:"files",params:["<dir>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"mkdir: missing operand",exitCode:1};for(let i=0;i<r.length;i++){let s=rr(r,i);if(!s)return{stderr:"mkdir: missing operand",exitCode:1};let o=he(e,s);Fe(n,o,"mkdir"),t.vfs.mkdir(o)}return{exitCode:0}}};var _d={name:"mv",description:"Move or rename files",category:"files",params:["<source> <dest>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=r.filter(l=>!l.startsWith("-")),[s,o]=i;if(!s||!o)return{stderr:"mv: missing operand",exitCode:1};let a=he(e,s),c=he(e,o);try{if(Fe(n,a,"mv"),Fe(n,c,"mv"),!t.vfs.exists(a))return{stderr:`mv: ${s}: No such file or directory`,exitCode:1};let l=t.vfs.exists(c)&&t.vfs.stat(c).type==="directory"?`${c}/${s.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 bd=Yt(require("node:path"),1);var Sd={name:"nano",description:"Text editor",category:"files",params:["<file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=r[0];if(!i)return{stderr:"nano: missing file operand",exitCode:1};let s=he(e,i);Fe(n,s,"nano");let o=t.vfs.exists(s)?t.vfs.readFile(s):"",a=bd.posix.basename(s)||"buffer",c=`/tmp/sshmimic-nano-${Date.now()}-${a}.tmp`;return{openEditor:{targetPath:s,tempPath:c,initialContent:o},exitCode:0}}};var Wn=require("node:fs"),Wt=Yt(require("node:os"),1),Nd=Yt(require("node:path"),1);function YA(n){let t=Math.max(1,Math.floor(n/60)),e=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60,s=[];return e>0&&s.push(`${e} day${e>1?"s":""}`),r>0&&s.push(`${r} hour${r>1?"s":""}`),(i>0||s.length===0)&&s.push(`${i} min${i>1?"s":""}`),s.join(", ")}function xd(n){return`\x1B[${n}m \x1B[0m`}function jA(){let n=[40,41,42,43,44,45,46,47].map(xd).join(""),t=[100,101,102,103,104,105,106,107].map(xd).join("");return[n,t]}function wd(n,t,e){if(n.trim().length===0)return n;let r={r:255,g:255,b:255},i={r:168,g:85,b:247},s=e<=1?0:t/(e-1),o=Math.round(r.r+(i.r-r.r)*s),a=Math.round(r.g+(i.g-r.g)*s),c=Math.round(r.b+(i.b-r.b)*s);return`\x1B[38;2;${o};${a};${c}m${n}\x1B[0m`}function XA(n){if(n.trim().length===0)return n;let t=n.indexOf(":");if(t===-1)return n.includes("@")?Id(n):n;let e=n.substring(0,t+1),r=n.substring(t+1);return Id(e)+r}function Id(n){let t=new RegExp("\x1B\\[[\\d;]*m","g"),e=n.replace(t,"");if(e.trim().length===0)return n;let r={r:255,g:255,b:255},i={r:168,g:85,b:247},s="";for(let o=0;o<e.length;o+=1){let a=e.length<=1?0:o/(e.length-1),c=Math.round(r.r+(i.r-r.r)*a),l=Math.round(r.g+(i.g-r.g)*a),u=Math.round(r.b+(i.b-r.b)*a);s+=`\x1B[38;2;${c};${l};${u}m${e[o]}\x1B[0m`}return s}function Cd(n){return Math.max(0,Math.round(n/(1024*1024)))}function kd(){try{let n=(0,Wn.readFileSync)("/etc/os-release","utf8");for(let t of n.split(`
942
+ `)){if(!t.startsWith("PRETTY_NAME="))continue;return t.slice(12).trim().replace(/^"|"$/g,"")}}catch{return}}function vd(n){try{let t=(0,Wn.readFileSync)(n,"utf8").split(`
943
+ `)[0]?.trim();return!t||t.length===0?void 0:t}catch{return}}function JA(n){let t=vd("/sys/devices/virtual/dmi/id/sys_vendor"),e=vd("/sys/devices/virtual/dmi/id/product_name");return t&&e?`${t} ${e}`:e||n}function ZA(){let n=["/var/lib/dpkg/status","/usr/local/var/lib/dpkg/status"];for(let t of n)if((0,Wn.existsSync)(t))try{return(0,Wn.readFileSync)(t,"utf8").match(/^Package:\s+/gm)?.length??0}catch{}}function ey(){let n=["/snap","/var/lib/snapd/snaps"];for(let t of n)if((0,Wn.existsSync)(t))try{return(0,Wn.readdirSync)(t,{withFileTypes:!0}).filter(i=>i.isDirectory()).length}catch{}}function ty(){let n=ZA(),t=ey();return n!==void 0&&t!==void 0?`${n} (dpkg), ${t} (snap)`:n!==void 0?`${n} (dpkg)`:t!==void 0?`${t} (snap)`:"n/a"}function ny(){let n=Wt.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 ry(n){return!n||n.trim().length===0?"unknown":Nd.posix.basename(n.trim())}function iy(n){let t=Wt.totalmem(),e=Wt.freemem(),r=Math.max(0,t-e),i=n.shellProps,s=process.uptime();return n.uptimeSeconds===void 0&&(n.uptimeSeconds=Math.round(s)),{user:n.user,host:n.host,osName:i?.os??n.osName??`${kd()??Wt.type()} ${Wt.arch()}`,kernel:i?.kernel??n.kernel??Wt.release(),uptimeSeconds:n.uptimeSeconds??Wt.uptime(),packages:n.packages??ty(),shell:ry(n.shell),shellProps:n.shellProps??{kernel:n.kernel??Wt.release(),os:n.osName??`${kd()??Wt.type()} ${Wt.arch()}`,arch:Wt.arch()},resolution:n.resolution??"n/a (ssh)",terminal:n.terminal??"unknown",cpu:n.cpu??ny(),gpu:n.gpu??"n/a",memoryUsedMiB:n.memoryUsedMiB??Cd(r),memoryTotalMiB:n.memoryTotalMiB??Cd(t)}}function Bd(n){let t=iy(n),e=YA(t.uptimeSeconds),r=jA(),i=[" .. .:. "," .::.. .. .. ",". .... ... .. ",": .... .:. .. ",": .:.:........:. .. ",": .. ",". : ",". : ",".. : "," :. .. "," .. .. "," :-. :: "," .:. :. "," ..: ... "," ..: :.. "," :... :...."," .. ...."," . .. "," .:. .: "," :. .. "," ::. .. ","..... ..:... ","...:. .. ",".:...:. ::. .. "," ... ..:::::.. ..:::::::.. "],s=[`${t.user}@${t.host}`,"-------------------------",`OS: ${t.osName}`,`Host: ${JA(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(i.length,s.length),a=[];for(let c=0;c<o;c+=1){let l=i[c]??"",u=s[c]??"";if(u.length>0){let f=wd(l.padEnd(31," "),c,i.length),h=XA(u);a.push(`${f} ${h}`);continue}a.push(wd(l,c,i.length))}return a.join(`
944
+ `)}var Rd={name:"neofetch",description:"System info display",category:"system",params:["[--off]"],run:({args:n,authUser:t,hostname:e,shell:r,env:i})=>r.packageManager.isInstalled("neofetch")?ae(n,"--help")?{stdout:"Usage: neofetch [--off]",exitCode:0}:ae(n,"--off")?{stdout:`${t}@${e}`,exitCode:0}:{stdout:Bd({user:t,host:e,shell:i.vars.SHELL,shellProps:r.properties,terminal:i.vars.TERM,uptimeSeconds:Math.floor((Date.now()-r.startTime)/1e3),packages:`${r.packageManager?.installedCount()??0} (dpkg)`}),exitCode:0}:{stderr:`bash: neofetch: command not found
945
945
  Hint: install it with: apt install neofetch
946
- `,exitCode:127}};var hc=Yt(require("node:vm"),1);var Ys="v18.19.0",Bd={node:Ys,npm:"9.2.0",v8:"10.2.154.26-node.22"};function ny(n,t){let e={version:Ys,versions:Bd,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 js(i)},cwd:()=>"/root",hrtime:()=>[0,0]},r={log:(...i)=>n.push(i.map(Rn).join(" ")),error:(...i)=>t.push(i.map(Rn).join(" ")),warn:(...i)=>t.push(i.map(Rn).join(" ")),info:(...i)=>n.push(i.map(Rn).join(" ")),dir:i=>n.push(Rn(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:`
947
- `};case"util":return{format:(...o)=>o.map(Rn).join(" "),inspect:o=>Rn(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={},hc.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 js=class{constructor(t){this.code=t}code};function Rn(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(Rn).join(", ")} ]`;if(n instanceof Error)return`${n.name}: ${n.message}`;if(typeof n=="object")try{return`{ ${Object.entries(n).map(([e,r])=>`${e}: ${Rn(r)}`).join(", ")} }`}catch{return"[Object]"}return String(n)}function Xs(n){let t=[],e=[],r=ny(t,e),s=0;try{let i=hc.default.runInContext(n,r,{timeout:5e3});i!==void 0&&t.length===0&&t.push(Rn(i))}catch(i){i instanceof js?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(`
946
+ `,exitCode:127}};var mc=Yt(require("node:vm"),1);var Xs="v18.19.0",Pd={node:Xs,npm:"9.2.0",v8:"10.2.154.26-node.22"};function sy(n,t){let e={version:Xs,versions:Pd,platform:"linux",arch:"x64",env:{NODE_ENV:"production",HOME:"/root",PATH:"/usr/local/bin:/usr/bin:/bin"},argv:["node"],stdout:{write:s=>(n.push(s),!0)},stderr:{write:s=>(t.push(s),!0)},exit:(s=0)=>{throw new Js(s)},cwd:()=>"/root",hrtime:()=>[0,0]},r={log:(...s)=>n.push(s.map(Rn).join(" ")),error:(...s)=>t.push(s.map(Rn).join(" ")),warn:(...s)=>t.push(s.map(Rn).join(" ")),info:(...s)=>n.push(s.map(Rn).join(" ")),dir:s=>n.push(Rn(s))},i=s=>{switch(s){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:`
947
+ `};case"util":return{format:(...o)=>o.map(Rn).join(" "),inspect:o=>Rn(o)};case"fs":case"fs/promises":throw new Error(`Cannot require '${s}': filesystem access not available in virtual runtime`);case"child_process":case"net":case"http":case"https":throw new Error(`Cannot require '${s}': not available in virtual runtime`);default:throw new Error(`Cannot find module '${s}'`)}};return i.resolve=s=>{throw new Error(`Cannot resolve '${s}'`)},i.cache={},i.extensions={},mc.default.createContext({console:r,process:e,require:i,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 Js=class{constructor(t){this.code=t}code};function Rn(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(Rn).join(", ")} ]`;if(n instanceof Error)return`${n.name}: ${n.message}`;if(typeof n=="object")try{return`{ ${Object.entries(n).map(([e,r])=>`${e}: ${Rn(r)}`).join(", ")} }`}catch{return"[Object]"}return String(n)}function Zs(n){let t=[],e=[],r=sy(t,e),i=0;try{let s=mc.default.runInContext(n,r,{timeout:5e3});s!==void 0&&t.length===0&&t.push(Rn(s))}catch(s){s instanceof Js?i=s.code:s instanceof Error?(e.push(`${s.name}: ${s.message}`),i=1):(e.push(String(s)),i=1)}return{stdout:t.length?`${t.join(`
948
948
  `)}
949
949
  `:"",stderr:e.length?`${e.join(`
950
950
  `)}
951
- `:"",exitCode:s}}function ry(n){let t=n.trim();return!t.includes(`
952
- `)&&!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("//")?Xs(t):Xs(`(async () => { ${n} })()`)}var Rd={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
951
+ `:"",exitCode:i}}function oy(n){let t=n.trim();return!t.includes(`
952
+ `)&&!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("//")?Zs(t):Zs(`(async () => { ${n} })()`)}var Td={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
953
953
  Hint: install it with: apt install nodejs
954
- `,exitCode:127};if(ae(n,["--version","-v"]))return{stdout:`${Ys}
955
- `,exitCode:0};if(ae(n,["--versions"]))return{stdout:`${JSON.stringify(Bd,null,2)}
954
+ `,exitCode:127};if(ae(n,["--version","-v"]))return{stdout:`${Xs}
955
+ `,exitCode:0};if(ae(n,["--versions"]))return{stdout:`${JSON.stringify(Pd,null,2)}
956
956
  `,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
957
- `,exitCode:1};let{stdout:a,stderr:c,exitCode:l}=Xs(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
958
- `,exitCode:1};let{stdout:a,stderr:c,exitCode:l}=Xs(o);return{stdout:a||(l===0?`
959
- `:void 0),stderr:c||void 0,exitCode:l}}let i=n.find(o=>!o.startsWith("-"));if(i){let o=he(e,i);if(!t.vfs.exists(o))return{stderr:`node: cannot open file '${i}': No such file or directory
960
- `,exitCode:1};let a=t.vfs.readFile(o),{stdout:c,stderr:l,exitCode:u}=ry(a);return{stdout:c||void 0,stderr:l||void 0,exitCode:u}}return{stdout:[`Welcome to Node.js ${Ys}.`,'Type ".exit" to exit the REPL.',"> "].join(`
961
- `),exitCode:0}}};var Js="9.2.0",iy="18.19.0",Pd={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
957
+ `,exitCode:1};let{stdout:a,stderr:c,exitCode:l}=Zs(o);return{stdout:a||void 0,stderr:c||void 0,exitCode:l}}let i=n.findIndex(o=>o==="-p"||o==="--print");if(i!==-1){let o=n[i+1];if(!o)return{stderr:`node: -p requires an argument
958
+ `,exitCode:1};let{stdout:a,stderr:c,exitCode:l}=Zs(o);return{stdout:a||(l===0?`
959
+ `:void 0),stderr:c||void 0,exitCode:l}}let s=n.find(o=>!o.startsWith("-"));if(s){let o=he(e,s);if(!t.vfs.exists(o))return{stderr:`node: cannot open file '${s}': No such file or directory
960
+ `,exitCode:1};let a=t.vfs.readFile(o),{stdout:c,stderr:l,exitCode:u}=oy(a);return{stdout:c||void 0,stderr:l||void 0,exitCode:u}}return{stdout:[`Welcome to Node.js ${Xs}.`,'Type ".exit" to exit the REPL.',"> "].join(`
961
+ `),exitCode:0}}};var eo="9.2.0",ay="18.19.0",Od={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
962
962
  Hint: install it with: apt install npm
963
- `,exitCode:127};if(ae(n,["--version","-v"]))return{stdout:`${Js}
964
- `,exitCode:0};let e=n[0]?.toLowerCase();switch(e){case"version":case"-version":return{stdout:`{ npm: '${Js}', node: '${iy}', v8: '10.2.154.26' }
963
+ `,exitCode:127};if(ae(n,["--version","-v"]))return{stdout:`${eo}
964
+ `,exitCode:0};let e=n[0]?.toLowerCase();switch(e){case"version":case"-version":return{stdout:`{ npm: '${eo}', node: '${ay}', v8: '10.2.154.26' }
965
965
  `,exitCode:0};case"install":case"i":case"add":return{stderr:`npm warn: package installation is not available in the virtual runtime.
966
966
  npm warn: This environment simulates npm CLI behaviour only.
967
967
  `,exitCode:1};case"run":case"exec":case"x":return{stderr:`npm error: script execution is not available in the virtual runtime.
968
968
  `,exitCode:1};case"init":return{stdout:`Wrote to /home/user/package.json
969
969
  `,exitCode:0};case"list":case"ls":return{stdout:`${e==="ls"||e==="list"?"virtual-env@1.0.0":""}
970
970
  \u2514\u2500\u2500 (empty)
971
- `,exitCode:0};case"help":case void 0:return{stdout:`${[`npm ${Js}`,"","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(`
971
+ `,exitCode:0};case"help":case void 0:return{stdout:`${[`npm ${eo}`,"","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(`
972
972
  `)}
973
973
  `,exitCode:0};default:return{stderr:`npm error: unknown command: ${e}
974
- `,exitCode:1}}}},Td={name:"npx",description:"Node.js package runner (virtual)",category:"system",params:["<package> [args]"],run:({args:n,shell:t})=>t.packageManager.isInstalled("npm")?ae(n,["--version"])?{stdout:`${Js}
974
+ `,exitCode:1}}}},Md={name:"npx",description:"Node.js package runner (virtual)",category:"system",params:["<package> [args]"],run:({args:n,shell:t})=>t.packageManager.isInstalled("npm")?ae(n,["--version"])?{stdout:`${eo}
975
975
  `,exitCode:0}:{stderr:`npx: package execution is not available in the virtual runtime.
976
976
  `,exitCode:1}:{stderr:`bash: npx: command not found
977
977
  Hint: install it with: apt install npm
978
- `,exitCode:127}};var Od={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(`
979
- `)[0];return await e.users.setPassword(s,i),{stdout:`passwd: password updated successfully
980
- `,exitCode:0}}return{passwordChallenge:{prompt:"New password: ",confirmPrompt:"Retype new password: ",action:"passwd",targetUsername:s},exitCode:0}}};var Md={name:"ping",description:"Send ICMP ECHO_REQUEST (mock)",category:"network",params:["[-c <count>] <host>"],run:({args:n})=>{let{flagsWithValues:t,positionals:e}=en(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(`
981
- `),exitCode:0}}};function sy(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+=`
982
- `,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 u=n[i],f=t[e++]??"",h=(p,y=" ")=>{if(c<=0||p.length>=c)return p;let E=y.repeat(c-p.length);return o?p+E:E+p};switch(u){case"s":{let p=String(f);l>=0&&(p=p.slice(0,l)),r+=h(p);break}case"d":case"i":r+=h(String(parseInt(f,10)||0),a?"0":" ");break;case"f":{let p=l>=0?l:6;r+=h((parseFloat(f)||0).toFixed(p));break}case"o":r+=h((parseInt(f,10)||0).toString(8),a?"0":" ");break;case"x":r+=h((parseInt(f,10)||0).toString(16),a?"0":" ");break;case"X":r+=h((parseInt(f,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 Ld={name:"printf",description:"Format and print data",category:"shell",params:["<format> [args...]"],run:({args:n})=>{let t=n[0];return t?{stdout:sy(t,n.slice(1)),exitCode:0}:{stderr:"printf: missing format string",exitCode:1}}};var Dd={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=ae(e,["-u"])||e.includes("u")||e.includes("aux")||e.includes("au"),i=ae(e,["-a","-x"])||e.includes("a")||e.includes("aux");if(s){let u=["USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND"],f=1e3;for(let h of r){let p=h.username.padEnd(10).slice(0,10),y=(Math.random()*.5).toFixed(1),E=Math.floor(Math.random()*2e4+5e3),S=Math.floor(Math.random()*5e3+1e3);u.push(`${p} ${String(f).padStart(6)} 0.0 ${y.padStart(4)} ${String(E).padStart(6)} ${String(S).padStart(5)} ${h.tty.padEnd(8)} Ss 00:00 0:00 bash`),f++}return u.push(`root ${String(f).padStart(6)} 0.0 0.0 0 0 ? S 00:00 0:00 ps`),{stdout:u.join(`
983
- `),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(`
984
- `),exitCode:0}}};var Ud={name:"pwd",description:"Print working directory",category:"navigation",params:[],run:({cwd:n})=>({stdout:n,exitCode:0})};var oy="Python 3.11.2";var Zs="3.11.2 (default, Mar 13 2023, 12:18:29) [GCC 12.2.0]",Y={__pytype__:"none"};function bt(n=[]){return{__pytype__:"dict",data:new Map(n)}}function pc(n,t,e=1){return{__pytype__:"range",start:n,stop:t,step:e}}function yt(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="dict"}function ei(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="range"}function Pn(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="func"}function mc(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="class"}function $i(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="instance"}function qn(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="none"}function Ot(n){return n===null||qn(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(Ot).join(", ")}]`:yt(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${Ot(e)}`).join(", ")}}`:ei(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:Pn(n)?`<function ${n.name} at 0x...>`:mc(n)?`<class '${n.name}'>`:$i(n)?`<${n.cls.name} object at 0x...>`:String(n)}function Te(n){return n===null||qn(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(Ot).join(", ")}]`:yt(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${Ot(e)}`).join(", ")}}`:ei(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:Ot(n)}function hn(n){return n===null||qn(n)?!1:typeof n=="boolean"?n:typeof n=="number"?n!==0:typeof n=="string"||Array.isArray(n)?n.length>0:yt(n)?n.data.size>0:ei(n)?Fd(n)>0:!0}function Fd(n){if(n.step===0)return 0;let t=Math.ceil((n.stop-n.start)/n.step);return Math.max(0,t)}function ay(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 Tt(n){if(Array.isArray(n))return n;if(typeof n=="string")return[...n];if(ei(n))return ay(n);if(yt(n))return[...n.data.keys()];throw new _t("TypeError",`'${Ar(n)}' object is not iterable`)}function Ar(n){return n===null||qn(n)?"NoneType":typeof n=="boolean"?"bool":typeof n=="number"?Number.isInteger(n)?"int":"float":typeof n=="string"?"str":Array.isArray(n)?"list":yt(n)?"dict":ei(n)?"range":Pn(n)?"function":mc(n)?"type":$i(n)?n.cls.name:"object"}var _t=class{constructor(t,e){this.type=t;this.message=e}type;message;toString(){return`${this.type}: ${this.message}`}},Zr=class{constructor(t){this.value=t}value},Fi=class{},Hi=class{},Qi=class{constructor(t){this.code=t}code};function cy(n){let t=new Map,e=bt([["sep","/"],["linesep",`
985
- `],["curdir","."],["pardir",".."]]);return e.__methods__={getcwd:()=>n,getenv:r=>typeof r=="string"?process.env[r]??Y:Y,path:bt([["join",Y],["exists",Y],["dirname",Y],["basename",Y]]),listdir:()=>[]},t.set("__builtins__",Y),t.set("__name__","__main__"),t.set("__cwd__",n),t}function ly(n){let t=bt([["sep","/"],["curdir","."]]),e=bt([["sep","/"],["linesep",`
986
- `],["name","posix"]]);return e._cwd=n,t._cwd=n,e.path=t,e}function uy(){return bt([["version",Zs],["version_info",bt([["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 fy(){return bt([["pi",Math.PI],["e",Math.E],["tau",Math.PI*2],["inf",1/0],["nan",NaN],["sqrt",Y],["floor",Y],["ceil",Y],["log",Y],["pow",Y],["sin",Y],["cos",Y],["tan",Y],["fabs",Y],["factorial",Y]])}function dy(){return bt([["dumps",Y],["loads",Y]])}function hy(){return bt([["match",Y],["search",Y],["findall",Y],["sub",Y],["split",Y],["compile",Y]])}var $d={os:ly,sys:()=>uy(),math:()=>fy(),json:()=>dy(),re:()=>hy(),random:()=>bt([["random",Y],["randint",Y],["choice",Y],["shuffle",Y]]),time:()=>bt([["time",Y],["sleep",Y],["ctime",Y]]),datetime:()=>bt([["datetime",Y],["date",Y],["timedelta",Y]]),collections:()=>bt([["Counter",Y],["defaultdict",Y],["OrderedDict",Y]]),itertools:()=>bt([["chain",Y],["product",Y],["combinations",Y],["permutations",Y]]),functools:()=>bt([["reduce",Y],["partial",Y],["lru_cache",Y]]),string:()=>bt([["ascii_letters","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"],["digits","0123456789"],["punctuation","!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"]])},eo=class{constructor(t){this.cwd=t}cwd;output=[];stderr=[];modules=new Map;getOutput(){return this.output.join(`
978
+ `,exitCode:127}};var Ld={name:"passwd",description:"Change user password",category:"users",params:["[username]"],run:async({authUser:n,args:t,shell:e,stdin:r})=>{let i=t[0]??n;if(n!=="root"&&n!==i)return{stderr:"passwd: permission denied",exitCode:1};if(!e.users.listUsers().includes(i))return{stderr:`passwd: user '${i}' does not exist`,exitCode:1};if(r!==void 0&&r.trim().length>0){let s=r.trim().split(`
979
+ `)[0];return await e.users.setPassword(i,s),{stdout:`passwd: password updated successfully
980
+ `,exitCode:0}}return{passwordChallenge:{prompt:"New password: ",confirmPrompt:"Retype new password: ",action:"passwd",targetUsername:i},exitCode:0}}};var Dd={name:"ping",description:"Send ICMP ECHO_REQUEST (mock)",category:"network",params:["[-c <count>] <host>"],run:({args:n})=>{let{flagsWithValues:t,positionals:e}=en(n,{flagsWithValue:["-c","-i","-W"]}),r=e[0]??"localhost",i=t.get("-c"),s=i?Math.max(1,parseInt(i,10)||4):4,o=[`PING ${r}: 56 data bytes`];for(let a=0;a<s;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(`${s} packets transmitted, ${s} received, 0% packet loss`),{stdout:o.join(`
981
+ `),exitCode:0}}};function cy(n,t){let e=0,r="",i=0;for(;i<n.length;){if(n[i]==="\\"&&i+1<n.length)switch(n[i+1]){case"n":r+=`
982
+ `,i+=2;continue;case"t":r+=" ",i+=2;continue;case"r":r+="\r",i+=2;continue;case"\\":r+="\\",i+=2;continue;case"a":r+="\x07",i+=2;continue;case"b":r+="\b",i+=2;continue;case"f":r+="\f",i+=2;continue;case"v":r+="\v",i+=2;continue;default:r+=n[i],i++;continue}if(n[i]==="%"&&i+1<n.length){let s=i+1,o=!1;n[s]==="-"&&(o=!0,s++);let a=!1;n[s]==="0"&&(a=!0,s++);let c=0;for(;s<n.length&&/\d/.test(n[s]);)c=c*10+parseInt(n[s],10),s++;let l=-1;if(n[s]===".")for(s++,l=0;s<n.length&&/\d/.test(n[s]);)l=l*10+parseInt(n[s],10),s++;let u=n[s],f=t[e++]??"",h=(p,y=" ")=>{if(c<=0||p.length>=c)return p;let E=y.repeat(c-p.length);return o?p+E:E+p};switch(u){case"s":{let p=String(f);l>=0&&(p=p.slice(0,l)),r+=h(p);break}case"d":case"i":r+=h(String(parseInt(f,10)||0),a?"0":" ");break;case"f":{let p=l>=0?l:6;r+=h((parseFloat(f)||0).toFixed(p));break}case"o":r+=h((parseInt(f,10)||0).toString(8),a?"0":" ");break;case"x":r+=h((parseInt(f,10)||0).toString(16),a?"0":" ");break;case"X":r+=h((parseInt(f,10)||0).toString(16).toUpperCase(),a?"0":" ");break;case"%":r+="%",e--;break;default:r+=n[i],i++;continue}i=s+1;continue}r+=n[i],i++}return r}var Ud={name:"printf",description:"Format and print data",category:"shell",params:["<format> [args...]"],run:({args:n})=>{let t=n[0];return t?{stdout:cy(t,n.slice(1)),exitCode:0}:{stderr:"printf: missing format string",exitCode:1}}};var $d={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(),i=ae(e,["-u"])||e.includes("u")||e.includes("aux")||e.includes("au"),s=ae(e,["-a","-x"])||e.includes("a")||e.includes("aux");if(i){let u=["USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND"],f=1e3;for(let h of r){let p=h.username.padEnd(10).slice(0,10),y=(Math.random()*.5).toFixed(1),E=Math.floor(Math.random()*2e4+5e3),S=Math.floor(Math.random()*5e3+1e3);u.push(`${p} ${String(f).padStart(6)} 0.0 ${y.padStart(4)} ${String(E).padStart(6)} ${String(S).padStart(5)} ${h.tty.padEnd(8)} Ss 00:00 0:00 bash`),f++}return u.push(`root ${String(f).padStart(6)} 0.0 0.0 0 0 ? S 00:00 0:00 ps`),{stdout:u.join(`
983
+ `),exitCode:0}}let a=[" PID TTY TIME CMD"],c=1e3;for(let l of r)!s&&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(`
984
+ `),exitCode:0}}};var Fd={name:"pwd",description:"Print working directory",category:"navigation",params:[],run:({cwd:n})=>({stdout:n,exitCode:0})};var ly="Python 3.11.2";var to="3.11.2 (default, Mar 13 2023, 12:18:29) [GCC 12.2.0]",Y={__pytype__:"none"};function bt(n=[]){return{__pytype__:"dict",data:new Map(n)}}function gc(n,t,e=1){return{__pytype__:"range",start:n,stop:t,step:e}}function yt(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="dict"}function ti(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="range"}function Pn(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="func"}function Ac(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="class"}function Fi(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="instance"}function qn(n){return!!n&&typeof n=="object"&&!Array.isArray(n)&&n.__pytype__==="none"}function Ot(n){return n===null||qn(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(Ot).join(", ")}]`:yt(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${Ot(e)}`).join(", ")}}`:ti(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:Pn(n)?`<function ${n.name} at 0x...>`:Ac(n)?`<class '${n.name}'>`:Fi(n)?`<${n.cls.name} object at 0x...>`:String(n)}function Te(n){return n===null||qn(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(Ot).join(", ")}]`:yt(n)?`{${[...n.data.entries()].map(([t,e])=>`'${t}': ${Ot(e)}`).join(", ")}}`:ti(n)?`range(${n.start}, ${n.stop}${n.step!==1?`, ${n.step}`:""})`:Ot(n)}function hn(n){return n===null||qn(n)?!1:typeof n=="boolean"?n:typeof n=="number"?n!==0:typeof n=="string"||Array.isArray(n)?n.length>0:yt(n)?n.data.size>0:ti(n)?Qd(n)>0:!0}function Qd(n){if(n.step===0)return 0;let t=Math.ceil((n.stop-n.start)/n.step);return Math.max(0,t)}function uy(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 Tt(n){if(Array.isArray(n))return n;if(typeof n=="string")return[...n];if(ti(n))return uy(n);if(yt(n))return[...n.data.keys()];throw new _t("TypeError",`'${yr(n)}' object is not iterable`)}function yr(n){return n===null||qn(n)?"NoneType":typeof n=="boolean"?"bool":typeof n=="number"?Number.isInteger(n)?"int":"float":typeof n=="string"?"str":Array.isArray(n)?"list":yt(n)?"dict":ti(n)?"range":Pn(n)?"function":Ac(n)?"type":Fi(n)?n.cls.name:"object"}var _t=class{constructor(t,e){this.type=t;this.message=e}type;message;toString(){return`${this.type}: ${this.message}`}},ei=class{constructor(t){this.value=t}value},Hi=class{},Qi=class{},Wi=class{constructor(t){this.code=t}code};function fy(n){let t=new Map,e=bt([["sep","/"],["linesep",`
985
+ `],["curdir","."],["pardir",".."]]);return e.__methods__={getcwd:()=>n,getenv:r=>typeof r=="string"?process.env[r]??Y:Y,path:bt([["join",Y],["exists",Y],["dirname",Y],["basename",Y]]),listdir:()=>[]},t.set("__builtins__",Y),t.set("__name__","__main__"),t.set("__cwd__",n),t}function dy(n){let t=bt([["sep","/"],["curdir","."]]),e=bt([["sep","/"],["linesep",`
986
+ `],["name","posix"]]);return e._cwd=n,t._cwd=n,e.path=t,e}function hy(){return bt([["version",to],["version_info",bt([["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 py(){return bt([["pi",Math.PI],["e",Math.E],["tau",Math.PI*2],["inf",1/0],["nan",NaN],["sqrt",Y],["floor",Y],["ceil",Y],["log",Y],["pow",Y],["sin",Y],["cos",Y],["tan",Y],["fabs",Y],["factorial",Y]])}function my(){return bt([["dumps",Y],["loads",Y]])}function gy(){return bt([["match",Y],["search",Y],["findall",Y],["sub",Y],["split",Y],["compile",Y]])}var Hd={os:dy,sys:()=>hy(),math:()=>py(),json:()=>my(),re:()=>gy(),random:()=>bt([["random",Y],["randint",Y],["choice",Y],["shuffle",Y]]),time:()=>bt([["time",Y],["sleep",Y],["ctime",Y]]),datetime:()=>bt([["datetime",Y],["date",Y],["timedelta",Y]]),collections:()=>bt([["Counter",Y],["defaultdict",Y],["OrderedDict",Y]]),itertools:()=>bt([["chain",Y],["product",Y],["combinations",Y],["permutations",Y]]),functools:()=>bt([["reduce",Y],["partial",Y],["lru_cache",Y]]),string:()=>bt([["ascii_letters","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"],["digits","0123456789"],["punctuation","!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"]])},no=class{constructor(t){this.cwd=t}cwd;output=[];stderr=[];modules=new Map;getOutput(){return this.output.join(`
987
987
  `)+(this.output.length?`
988
988
  `:"")}getStderr(){return this.stderr.join(`
989
989
  `)+(this.stderr.length?`
990
- `:"")}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 Y;if(t==="True")return!0;if(t==="False")return!1;if(t==="...")return Y;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,`
991
- `).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,(u,f)=>{try{return Te(this.pyEval(f.trim(),e))}catch{return`{${f}}`}}),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 u=l.match(/^(.+?)\s+for\s+(\w+)\s+in\s+(.+?)(?:\s+if\s+(.+))?$/);if(u){let[,f,h,p,y]=u,E=Tt(this.pyEval(p.trim(),e)),S=[];for(let x of E){let P=new Map(e);P.set(h,x),!(y&&!hn(this.pyEval(y,P)))&&S.push(this.pyEval(f.trim(),P))}return S}return this.splitArgs(l).map(f=>this.pyEval(f,e))}if(t.startsWith("(")&&t.endsWith(")")){let l=t.slice(1,-1).trim();if(!l)return[];let u=this.splitArgs(l);return u.length===1&&!l.endsWith(",")?this.pyEval(u[0],e):u.map(f=>this.pyEval(f,e))}if(t.startsWith("{")&&t.endsWith("}")){let l=t.slice(1,-1).trim();if(!l)return bt();let u=bt();for(let f of this.splitArgs(l)){let h=f.indexOf(":");if(h===-1)continue;let p=Te(this.pyEval(f.slice(0,h).trim(),e)),y=this.pyEval(f.slice(h+1).trim(),e);u.data.set(p,y)}return u}let i=t.match(/^not\s+(.+)$/);if(i)return!hn(this.pyEval(i[1],e));let o=[["or"],["and"],["in","not in","is not","is","==","!=","<=",">=","<",">"],["+","-"],["**"],["*","//","/","%"]];for(let l of o){let u=this.tryBinaryOp(t,l,e);if(u!==void 0)return u}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 u=this.pyEval(t.slice(0,l),e),f=t.slice(l+1,-1);return this.subscript(u,f,e)}}let a=t.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*)\)$/);if(a){let[,l,u]=a,f=(u?.trim()?this.splitArgs(u):[]).map(h=>this.pyEval(h,e));return this.callBuiltin(l,f,e)}let c=this.findDotAccess(t);if(c){let{objExpr:l,attr:u,callPart:f}=c,h=this.pyEval(l,e);if(f!==void 0){let p=f.slice(1,-1),y=p.trim()?this.splitArgs(p).map(E=>this.pyEval(E,e)):[];return this.callMethod(h,u,y,e)}return this.getAttr(h,u,e)}if(/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)){if(e.has(t))return e.get(t);throw new _t("NameError",`name '${t}' is not defined`)}if(/^[A-Za-z_][A-Za-z0-9_.]+$/.test(t)){let l=t.split("."),u=e.get(l[0])??(()=>{throw new _t("NameError",`name '${l[0]}' is not defined`)})();for(let f of l.slice(1))u=this.getAttr(u,f,e);return u}return Y}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 u=t[a-1],f=t[a+l.length];if(/^[a-z]/.test(l)&&(u&&/\w/.test(u)||f&&/\w/.test(f)))continue;let p=t.slice(0,a).trim(),y=t.slice(a+l.length).trim();if(!p||!y)continue;return this.applyBinaryOp(l,p,y,r)}}}}applyBinaryOp(t,e,r,s){if(t==="and"){let a=this.pyEval(e,s);return hn(a)?this.pyEval(r,s):a}if(t==="or"){let a=this.pyEval(e,s);return hn(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 _t("ZeroDivisionError","division by zero");return i/o}case"//":{if(o===0)throw new _t("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 _t("ZeroDivisionError","integer division or modulo by zero");return i%o}case"**":return i**o;case"==":return Ot(i)===Ot(o)||i===o;case"!=":return Ot(i)!==Ot(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||qn(i)&&qn(o);case"is not":return!(i===o||qn(i)&&qn(o))}return Y}pyIn(t,e){return typeof t=="string"?typeof e=="string"&&t.includes(e):Array.isArray(t)?t.some(r=>Ot(r)===Ot(e)):yt(t)?t.data.has(Te(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):Y}let s=this.pyEval(e,r);if(Array.isArray(t)){let i=s;return i<0&&(i=t.length+i),t[i]??Y}if(typeof t=="string"){let i=s;return i<0&&(i=t.length+i),t[i]??Y}if(yt(t))return t.data.get(Te(s))??Y;throw new _t("TypeError",`'${Ar(t)}' is not subscriptable`)}getAttr(t,e,r){return yt(t)?t.data.has(e)?t.data.get(e):e==="path"&&t.path?t.path:Y:$i(t)?t.attrs.get(e)??Y:typeof t=="string"?{__class__:{__pytype__:"class",name:"str"}}[e]??Y:Y}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(`
992
- `);case"join":return Tt(r[0]??[]).map(Te).join(t);case"replace":return t.replaceAll(Te(r[0]??""),Te(r[1]??""));case"startswith":return t.startsWith(Te(r[0]??""));case"endswith":return t.endsWith(Te(r[0]??""));case"find":return t.indexOf(Te(r[0]??""));case"index":{let i=t.indexOf(Te(r[0]??""));if(i===-1)throw new _t("ValueError","substring not found");return i}case"count":return t.split(Te(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=Te(r[1]??" ");return t.padStart(Math.floor((i+t.length)/2),o).padEnd(i,o)}case"ljust":return t.padEnd(r[0]??0,Te(r[1]??" "));case"rjust":return t.padStart(r[0]??0,Te(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]??Y),Y;case"extend":for(let i of Tt(r[0]??[]))t.push(i);return Y;case"insert":return t.splice(r[0]??0,0,r[1]??Y),Y;case"pop":{let i=r[0]!==void 0?r[0]:-1,o=i<0?t.length+i:i;return t.splice(o,1)[0]??Y}case"remove":{let i=t.findIndex(o=>Ot(o)===Ot(r[0]??Y));return i!==-1&&t.splice(i,1),Y}case"index":{let i=t.findIndex(o=>Ot(o)===Ot(r[0]??Y));if(i===-1)throw new _t("ValueError","is not in list");return i}case"count":return t.filter(i=>Ot(i)===Ot(r[0]??Y)).length;case"sort":return t.sort((i,o)=>typeof i=="number"&&typeof o=="number"?i-o:Te(i).localeCompare(Te(o))),Y;case"reverse":return t.reverse(),Y;case"copy":return[...t];case"clear":return t.splice(0),Y}if(yt(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(Te(r[0]??""))??r[1]??Y;case"update":{if(yt(r[0]??Y))for(let[i,o]of r[0].data)t.data.set(i,o);return Y}case"pop":{let i=Te(r[0]??""),o=t.data.get(i)??r[1]??Y;return t.data.delete(i),o}case"clear":return t.data.clear(),Y;case"copy":return bt([...t.data.entries()]);case"setdefault":{let i=Te(r[0]??"");return t.data.has(i)||t.data.set(i,r[1]??Y),t.data.get(i)??Y}}if(yt(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]??Y:Y;case"listdir":return[];case"path":return t}if(yt(t))switch(e){case"join":return r.map(Te).join("/").replace(/\/+/g,"/");case"exists":return!1;case"dirname":return Te(r[0]??"").split("/").slice(0,-1).join("/")||"/";case"basename":return Te(r[0]??"").split("/").pop()??"";case"abspath":return Te(r[0]??"");case"splitext":{let i=Te(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(yt(t)&&t.data.has("version")&&t.data.get("version")===Zs&&e==="exit")throw new Qi(r[0]??0);if(yt(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(yt(t)){if(e==="dumps"){let i=yt(r[1]??Y)?r[1]:void 0,o=i?i.data.get("indent"):void 0;return JSON.stringify(this.pyToJs(r[0]??Y),null,o)}if(e==="loads")return this.jsToPy(JSON.parse(Te(r[0]??"")))}if($i(t)){let i=t.attrs.get(e)??t.cls.methods.get(e)??Y;if(Pn(i)){let o=new Map(i.closure);return o.set("self",t),i.params.slice(1).forEach((a,c)=>o.set(a,r[c]??Y)),this.execBlock(i.body,o)}}throw new _t("AttributeError",`'${Ar(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 Te(o??Y);case"r":return Ot(o??Y);default:return String(o)}})}pyToJs(t){return qn(t)?null:yt(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?Y:typeof t=="boolean"||typeof t=="number"||typeof t=="string"?t:Array.isArray(t)?t.map(e=>this.jsToPy(e)):typeof t=="object"?bt(Object.entries(t).map(([e,r])=>[e,this.jsToPy(r)])):Y}callBuiltin(t,e,r){if(r.has(t)){let s=r.get(t)??Y;return Pn(s)?this.callFunc(s,e,r):mc(s)?this.instantiate(s,e,r):s}switch(t){case"print":return this.output.push(e.map(Te).join(" ")+`
993
- `.replace(/\\n/g,"")),Y;case"input":return this.output.push(Te(e[0]??"")),"";case"int":{if(e.length===0)return 0;let s=e[1]??10,i=parseInt(Te(e[0]??0),s);return Number.isNaN(i)?(()=>{throw new _t("ValueError","invalid literal for int()")})():i}case"float":{if(e.length===0)return 0;let s=parseFloat(Te(e[0]??0));return Number.isNaN(s)?(()=>{throw new _t("ValueError","could not convert to float")})():s}case"str":return e.length===0?"":Te(e[0]??Y);case"bool":return e.length===0?!1:hn(e[0]??Y);case"list":return e.length===0?[]:Tt(e[0]??[]);case"tuple":return e.length===0?[]:Tt(e[0]??[]);case"set":return e.length===0?[]:[...new Set(Tt(e[0]??[]).map(Ot))].map(s=>Tt(e[0]??[]).find(o=>Ot(o)===s)??Y);case"dict":return e.length===0?bt():yt(e[0]??Y)?e[0]:bt();case"bytes":return typeof e[0]=="string"?e[0]:Te(e[0]??"");case"bytearray":return e.length===0?"":Te(e[0]??"");case"type":return e.length===1?`<class '${Ar(e[0]??Y)}'>`:Y;case"isinstance":return Ar(e[0]??Y)===Te(e[1]??"");case"issubclass":return!1;case"callable":return Pn(e[0]??Y);case"hasattr":return yt(e[0]??Y)?e[0].data.has(Te(e[1]??"")):!1;case"getattr":return yt(e[0]??Y)?e[0].data.get(Te(e[1]??""))??e[2]??Y:e[2]??Y;case"setattr":return yt(e[0]??Y)&&e[0].data.set(Te(e[1]??""),e[2]??Y),Y;case"len":{let s=e[0]??Y;if(typeof s=="string"||Array.isArray(s))return s.length;if(yt(s))return s.data.size;if(ei(s))return Fd(s);throw new _t("TypeError",`object of type '${Ar(s)}' has no len()`)}case"range":return e.length===1?pc(0,e[0]):e.length===2?pc(e[0],e[1]):pc(e[0],e[1],e[2]);case"enumerate":{let s=e[1]??0;return Tt(e[0]??[]).map((i,o)=>[o+s,i])}case"zip":{let s=e.map(Tt),i=Math.min(...s.map(o=>o.length));return Array.from({length:i},(o,a)=>s.map(c=>c[a]??Y))}case"map":{let s=e[0]??Y;return Tt(e[1]??[]).map(i=>Pn(s)?this.callFunc(s,[i],r):Y)}case"filter":{let s=e[0]??Y;return Tt(e[1]??[]).filter(i=>Pn(s)?hn(this.callFunc(s,[i],r)):hn(i))}case"reduce":{let s=e[0]??Y,i=Tt(e[1]??[]);if(i.length===0)return e[2]??Y;let o=e[2]!==void 0?e[2]:i[0];for(let a of e[2]!==void 0?i:i.slice(1))o=Pn(s)?this.callFunc(s,[o,a],r):Y;return o}case"sorted":{let s=[...Tt(e[0]??[])],i=e[1]??Y,o=yt(i)?i.data.get("key")??Y:i;return s.sort((a,c)=>{let l=Pn(o)?this.callFunc(o,[a],r):a,u=Pn(o)?this.callFunc(o,[c],r):c;return typeof l=="number"&&typeof u=="number"?l-u:Te(l).localeCompare(Te(u))}),s}case"reversed":return[...Tt(e[0]??[])].reverse();case"any":return Tt(e[0]??[]).some(hn);case"all":return Tt(e[0]??[]).every(hn);case"sum":return Tt(e[0]??[]).reduce((s,i)=>s+i,e[1]??0);case"max":return(e.length===1?Tt(e[0]??[]):e).reduce((i,o)=>i>=o?i:o);case"min":return(e.length===1?Tt(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 Te(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]:Te(e[0]??"").split("").reduce((s,i)=>s*31+i.charCodeAt(0)|0,0);case"open":throw new _t("PermissionError","open() not available in virtual runtime");case"repr":return Ot(e[0]??Y);case"iter":return e[0]??Y;case"next":return Array.isArray(e[0])&&e[0].length>0?e[0].shift():e[1]??(()=>{throw new _t("StopIteration","")})();case"vars":return bt([...r.entries()].map(([s,i])=>[s,i]));case"globals":return bt([...r.entries()].map(([s,i])=>[s,i]));case"locals":return bt([...r.entries()].map(([s,i])=>[s,i]));case"dir":{if(e.length===0)return[...r.keys()];let s=e[0]??Y;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"]:yt(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 _t(t,Te(e[0]??""));case"exec":return this.execScript(Te(e[0]??""),r),Y;case"eval":return this.pyEval(Te(e[0]??""),r);default:throw new _t("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]??Y)});try{return this.execBlock(t.body,s)}catch(i){if(i instanceof Zr)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(`
994
- `);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 Zr)return r.value;throw r}return Y}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 Hi;let a=i.match(/^return(?:\s+(.+))?$/);if(a)throw new Zr(a[1]?this.pyEval(a[1],r):Y);let c=i.match(/^raise(?:\s+(.+))?$/);if(c){if(c[1]){let v=this.pyEval(c[1],r);throw new _t(typeof v=="string"?v:Ar(v),Te(v))}throw new _t("RuntimeError","")}let l=i.match(/^assert\s+(.+?)(?:,\s*(.+))?$/);if(l){if(!hn(this.pyEval(l[1],r)))throw new _t("AssertionError",l[2]?Te(this.pyEval(l[2],r)):"");return e+1}let u=i.match(/^del\s+(.+)$/);if(u)return r.delete(u[1].trim()),e+1;let f=i.match(/^import\s+(\w+)(?:\s+as\s+(\w+))?$/);if(f){let[,v,b]=f,w=$d[v];if(w){let k=w(this.cwd);this.modules.set(v,k),r.set(b??v,k)}return e+1}let h=i.match(/^from\s+(\w+)\s+import\s+(.+)$/);if(h){let[,v,b]=h,w=$d[v];if(w){let k=w(this.cwd);if(b?.trim()==="*")for(let[N,R]of k.data)r.set(N,R);else for(let N of b.split(",").map(R=>R.trim()))r.set(N,k.data.get(N)??Y)}return e+1}let p=i.match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(p){let[,v,b]=p,w=b.split(",").map(R=>R.trim()).filter(Boolean),k=this.collectBlock(t,e+1,o),N={__pytype__:"func",name:v,params:w,body:k,closure:new Map(r)};return r.set(v,N),e+1+k.length}let y=i.match(/^class\s+(\w+)(?:\(([^)]*)\))?\s*:$/);if(y){let[,v,b]=y,w=b?b.split(",").map(ie=>ie.trim()):[],k=this.collectBlock(t,e+1,o),N={__pytype__:"class",name:v,methods:new Map,bases:w},R=0;for(;R<k.length;){let j=k[R].trim().match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(j){let[,X,re]=j,fe=re.split(",").map(B=>B.trim()).filter(Boolean),H=this.collectBlock(k,R+1,0);N.methods.set(X,{__pytype__:"func",name:X,params:fe,body:H,closure:new Map(r)}),R+=1+H.length}else R++}return r.set(v,N),e+1+k.length}if(i.startsWith("if ")&&i.endsWith(":")){let v=i.slice(3,-1).trim(),b=this.collectBlock(t,e+1,o),w=b.length+1;if(hn(this.pyEval(v,r))){this.execBlock(b,new Map(r).also?.(R=>{for(let[ie,j]of r)R.set(ie,j)})??r),this.runBlockInScope(b,r);let N=e+1+b.length;for(;N<t.length;){let R=t[N].trim();if(this.getIndent(t[N])<o||!R.startsWith("elif")&&!R.startsWith("else"))break;let ie=this.collectBlock(t,N+1,o);N+=1+ie.length}return N}let k=e+1+b.length;for(;k<t.length;){let N=t[k],R=N.trim();if(this.getIndent(N)!==o)break;let ie=R.match(/^elif\s+(.+):$/);if(ie){let j=this.collectBlock(t,k+1,o);if(hn(this.pyEval(ie[1],r))){for(this.runBlockInScope(j,r),k+=1+j.length;k<t.length;){let X=t[k].trim();if(this.getIndent(t[k])!==o||!X.startsWith("elif")&&!X.startsWith("else"))break;let re=this.collectBlock(t,k+1,o);k+=1+re.length}return k}k+=1+j.length;continue}if(R==="else:"){let j=this.collectBlock(t,k+1,o);return this.runBlockInScope(j,r),k+1+j.length}break}return k}let E=i.match(/^for\s+(.+?)\s+in\s+(.+?)\s*:$/);if(E){let[,v,b]=E,w=Tt(this.pyEval(b.trim(),r)),k=this.collectBlock(t,e+1,o),N=[],R=e+1+k.length;R<t.length&&t[R]?.trim()==="else:"&&(N=this.collectBlock(t,R+1,o),R+=1+N.length);let ie=!1;for(let j of w){if(v.includes(",")){let X=v.split(",").map(fe=>fe.trim()),re=Array.isArray(j)?j:[j];X.forEach((fe,H)=>r.set(fe,re[H]??Y))}else r.set(v.trim(),j);try{this.runBlockInScope(k,r)}catch(X){if(X instanceof Fi){ie=!0;break}if(X instanceof Hi)continue;throw X}}return!ie&&N.length&&this.runBlockInScope(N,r),R}let S=i.match(/^while\s+(.+?)\s*:$/);if(S){let v=S[1],b=this.collectBlock(t,e+1,o),w=0;for(;hn(this.pyEval(v,r))&&w++<1e5;)try{this.runBlockInScope(b,r)}catch(k){if(k instanceof Fi)break;if(k instanceof Hi)continue;throw k}return e+1+b.length}if(i==="try:"){let v=this.collectBlock(t,e+1,o),b=e+1+v.length,w=[],k=[],N=[];for(;b<t.length;){let ie=t[b],j=ie.trim();if(this.getIndent(ie)!==o)break;if(j.startsWith("except")){let X=j.match(/^except(?:\s+(\w+)(?:\s+as\s+(\w+))?)?\s*:$/),re=X?.[1]??null,fe=X?.[2],H=this.collectBlock(t,b+1,o);w.push({exc:re,body:H}),fe&&r.set(fe,""),b+=1+H.length}else if(j==="else:")N=this.collectBlock(t,b+1,o),b+=1+N.length;else if(j==="finally:")k=this.collectBlock(t,b+1,o),b+=1+k.length;else break}let R=null;try{this.runBlockInScope(v,r),N.length&&this.runBlockInScope(N,r)}catch(ie){if(ie instanceof _t){R=ie;let j=!1;for(let X of w)if(X.exc===null||X.exc===ie.type||X.exc==="Exception"){this.runBlockInScope(X.body,r),j=!0;break}if(!j)throw ie}else throw ie}finally{k.length&&this.runBlockInScope(k,r)}return b}let x=i.match(/^with\s+(.+?)\s+as\s+(\w+)\s*:$/);if(x){let v=this.collectBlock(t,e+1,o);return r.set(x[2],Y),this.runBlockInScope(v,r),e+1+v.length}let P=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(\+=|-=|\*=|\/\/=|\/=|%=|\*\*=|&=|\|=)\s*(.+)$/);if(P){let[,v,b,w]=P,k=r.get(v)??0,N=this.pyEval(w,r),R;switch(b){case"+=":R=typeof k=="string"?k+Te(N):k+N;break;case"-=":R=k-N;break;case"*=":R=k*N;break;case"/=":R=k/N;break;case"//=":R=Math.floor(k/N);break;case"%=":R=k%N;break;case"**=":R=k**N;break;default:R=N}return r.set(v,R),e+1}let q=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\[(.+)\]\s*=\s*(.+)$/);if(q){let[,v,b,w]=q,k=r.get(v)??Y,N=this.pyEval(w,r)??Y,R=this.pyEval(b,r)??Y;return Array.isArray(k)?k[R]=N:yt(k)&&k.data.set(Te(R),N),e+1}let C=i.match(/^([A-Za-z_][A-Za-z0-9_.]+)\s*=\s*(.+)$/);if(C){let v=C[1].lastIndexOf(".");if(v!==-1){let b=C[1].slice(0,v),w=C[1].slice(v+1),k=this.pyEval(C[2],r),N=this.pyEval(b,r);return yt(N)?N.data.set(w,k):$i(N)&&N.attrs.set(w,k),e+1}}let $=i.match(/^([A-Za-z_][A-Za-z0-9_,\s]*),\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.+)$/);if($){let v=this.pyEval($[3],r),b=i.split("=")[0].split(",").map(k=>k.trim()),w=Tt(v);return b.forEach((k,N)=>r.set(k,w[N]??Y)),e+1}let F=i.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(?::[^=]+)?\s*=\s*(.+)$/);if(F){let[,v,b]=F;return r.set(v,this.pyEval(b,r)),e+1}try{this.pyEval(i,r)}catch(v){if(v instanceof _t||v instanceof Qi)throw v}return e+1}runBlockInScope(t,e){this.execLines(t,0,e)}run(t){let e=cy(this.cwd);try{this.execScript(t,e)}catch(r){return r instanceof Qi?{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:r.code}:r instanceof _t?(this.stderr.push(r.toString()),{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:1}):r instanceof Zr?{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}}},Hd={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
990
+ `:"")}splitArgs(t){let e=[],r=0,i="",s=!1,o="";for(let a=0;a<t.length;a++){let c=t[a];s?(i+=c,c===o&&t[a-1]!=="\\"&&(s=!1)):c==='"'||c==="'"?(s=!0,o=c,i+=c):"([{".includes(c)?(r++,i+=c):")]}".includes(c)?(r--,i+=c):c===","&&r===0?(e.push(i.trim()),i=""):i+=c}return i.trim()&&e.push(i.trim()),e}pyEval(t,e){if(t=t.trim(),!t||t==="None")return Y;if(t==="True")return!0;if(t==="False")return!1;if(t==="...")return Y;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,`
991
+ `).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,(u,f)=>{try{return Te(this.pyEval(f.trim(),e))}catch{return`{${f}}`}}),l}let i=t.match(/^b(['"])(.*)\1$/s);if(i)return i[2];if(t.startsWith("[")&&t.endsWith("]")){let l=t.slice(1,-1).trim();if(!l)return[];let u=l.match(/^(.+?)\s+for\s+(\w+)\s+in\s+(.+?)(?:\s+if\s+(.+))?$/);if(u){let[,f,h,p,y]=u,E=Tt(this.pyEval(p.trim(),e)),S=[];for(let x of E){let P=new Map(e);P.set(h,x),!(y&&!hn(this.pyEval(y,P)))&&S.push(this.pyEval(f.trim(),P))}return S}return this.splitArgs(l).map(f=>this.pyEval(f,e))}if(t.startsWith("(")&&t.endsWith(")")){let l=t.slice(1,-1).trim();if(!l)return[];let u=this.splitArgs(l);return u.length===1&&!l.endsWith(",")?this.pyEval(u[0],e):u.map(f=>this.pyEval(f,e))}if(t.startsWith("{")&&t.endsWith("}")){let l=t.slice(1,-1).trim();if(!l)return bt();let u=bt();for(let f of this.splitArgs(l)){let h=f.indexOf(":");if(h===-1)continue;let p=Te(this.pyEval(f.slice(0,h).trim(),e)),y=this.pyEval(f.slice(h+1).trim(),e);u.data.set(p,y)}return u}let s=t.match(/^not\s+(.+)$/);if(s)return!hn(this.pyEval(s[1],e));let o=[["or"],["and"],["in","not in","is not","is","==","!=","<=",">=","<",">"],["+","-"],["**"],["*","//","/","%"]];for(let l of o){let u=this.tryBinaryOp(t,l,e);if(u!==void 0)return u}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 u=this.pyEval(t.slice(0,l),e),f=t.slice(l+1,-1);return this.subscript(u,f,e)}}let a=t.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*\(([\s\S]*)\)$/);if(a){let[,l,u]=a,f=(u?.trim()?this.splitArgs(u):[]).map(h=>this.pyEval(h,e));return this.callBuiltin(l,f,e)}let c=this.findDotAccess(t);if(c){let{objExpr:l,attr:u,callPart:f}=c,h=this.pyEval(l,e);if(f!==void 0){let p=f.slice(1,-1),y=p.trim()?this.splitArgs(p).map(E=>this.pyEval(E,e)):[];return this.callMethod(h,u,y,e)}return this.getAttr(h,u,e)}if(/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)){if(e.has(t))return e.get(t);throw new _t("NameError",`name '${t}' is not defined`)}if(/^[A-Za-z_][A-Za-z0-9_.]+$/.test(t)){let l=t.split("."),u=e.get(l[0])??(()=>{throw new _t("NameError",`name '${l[0]}' is not defined`)})();for(let f of l.slice(1))u=this.getAttr(u,f,e);return u}return Y}findMatchingBracket(t,e){let r=e==="["?"]":e==="("?")":"}",i=0;for(let s=t.length-1;s>=0;s--)if(t[s]===r&&i++,t[s]===e&&(i--,i===0))return s;return-1}findDotAccess(t){let e=0,r=!1,i="";for(let s=t.length-1;s>0;s--){let o=t[s];if(r){o===i&&t[s-1]!=="\\"&&(r=!1);continue}if(o==='"'||o==="'"){r=!0,i=o;continue}if(")]}".includes(o)){e++;continue}if("([{".includes(o)){e--;continue}if(e!==0||o!==".")continue;let a=t.slice(0,s).trim(),l=t.slice(s+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 i=0,s=!1,o="";for(let a=t.length-1;a>=0;a--){let c=t[a];if(s){c===o&&t[a-1]!=="\\"&&(s=!1);continue}if(c==='"'||c==="'"){s=!0,o=c;continue}if(")]}".includes(c)){i++;continue}if("([{".includes(c)){i--;continue}if(i===0){for(let l of e)if(t.slice(a,a+l.length)===l){if(l==="*"&&(t[a+1]==="*"||t[a-1]==="*"))continue;let u=t[a-1],f=t[a+l.length];if(/^[a-z]/.test(l)&&(u&&/\w/.test(u)||f&&/\w/.test(f)))continue;let p=t.slice(0,a).trim(),y=t.slice(a+l.length).trim();if(!p||!y)continue;return this.applyBinaryOp(l,p,y,r)}}}}applyBinaryOp(t,e,r,i){if(t==="and"){let a=this.pyEval(e,i);return hn(a)?this.pyEval(r,i):a}if(t==="or"){let a=this.pyEval(e,i);return hn(a)?a:this.pyEval(r,i)}let s=this.pyEval(e,i),o=this.pyEval(r,i);switch(t){case"+":return typeof s=="string"&&typeof o=="string"?s+o:Array.isArray(s)&&Array.isArray(o)?[...s,...o]:s+o;case"-":return s-o;case"*":if(typeof s=="string"&&typeof o=="number")return s.repeat(o);if(Array.isArray(s)&&typeof o=="number"){let a=[];for(let c=0;c<o;c++)a.push(...s);return a}return s*o;case"/":{if(o===0)throw new _t("ZeroDivisionError","division by zero");return s/o}case"//":{if(o===0)throw new _t("ZeroDivisionError","integer division or modulo by zero");return Math.floor(s/o)}case"%":{if(typeof s=="string")return this.pyStringFormat(s,Array.isArray(o)?o:[o]);if(o===0)throw new _t("ZeroDivisionError","integer division or modulo by zero");return s%o}case"**":return s**o;case"==":return Ot(s)===Ot(o)||s===o;case"!=":return Ot(s)!==Ot(o)&&s!==o;case"<":return s<o;case"<=":return s<=o;case">":return s>o;case">=":return s>=o;case"in":return this.pyIn(o,s);case"not in":return!this.pyIn(o,s);case"is":return s===o||qn(s)&&qn(o);case"is not":return!(s===o||qn(s)&&qn(o))}return Y}pyIn(t,e){return typeof t=="string"?typeof e=="string"&&t.includes(e):Array.isArray(t)?t.some(r=>Ot(r)===Ot(e)):yt(t)?t.data.has(Te(e)):!1}subscript(t,e,r){if(e.includes(":")){let s=e.split(":").map(c=>c.trim()),o=s[0]?this.pyEval(s[0],r):void 0,a=s[1]?this.pyEval(s[1],r):void 0;return typeof t=="string"||Array.isArray(t)?t.slice(o,a):Y}let i=this.pyEval(e,r);if(Array.isArray(t)){let s=i;return s<0&&(s=t.length+s),t[s]??Y}if(typeof t=="string"){let s=i;return s<0&&(s=t.length+s),t[s]??Y}if(yt(t))return t.data.get(Te(i))??Y;throw new _t("TypeError",`'${yr(t)}' is not subscriptable`)}getAttr(t,e,r){return yt(t)?t.data.has(e)?t.data.get(e):e==="path"&&t.path?t.path:Y:Fi(t)?t.attrs.get(e)??Y:typeof t=="string"?{__class__:{__pytype__:"class",name:"str"}}[e]??Y:Y}callMethod(t,e,r,i){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((s,o)=>o>0||s!=="");case"splitlines":return t.split(`
992
+ `);case"join":return Tt(r[0]??[]).map(Te).join(t);case"replace":return t.replaceAll(Te(r[0]??""),Te(r[1]??""));case"startswith":return t.startsWith(Te(r[0]??""));case"endswith":return t.endsWith(Te(r[0]??""));case"find":return t.indexOf(Te(r[0]??""));case"index":{let s=t.indexOf(Te(r[0]??""));if(s===-1)throw new _t("ValueError","substring not found");return s}case"count":return t.split(Te(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 s=r[0]??0,o=Te(r[1]??" ");return t.padStart(Math.floor((s+t.length)/2),o).padEnd(s,o)}case"ljust":return t.padEnd(r[0]??0,Te(r[1]??" "));case"rjust":return t.padStart(r[0]??0,Te(r[1]??" "));case"zfill":return t.padStart(r[0]??0,"0");case"title":return t.replace(/\b\w/g,s=>s.toUpperCase());case"capitalize":return t[0]?.toUpperCase()+t.slice(1).toLowerCase();case"swapcase":return[...t].map(s=>s===s.toUpperCase()?s.toLowerCase():s.toUpperCase()).join("")}if(Array.isArray(t))switch(e){case"append":return t.push(r[0]??Y),Y;case"extend":for(let s of Tt(r[0]??[]))t.push(s);return Y;case"insert":return t.splice(r[0]??0,0,r[1]??Y),Y;case"pop":{let s=r[0]!==void 0?r[0]:-1,o=s<0?t.length+s:s;return t.splice(o,1)[0]??Y}case"remove":{let s=t.findIndex(o=>Ot(o)===Ot(r[0]??Y));return s!==-1&&t.splice(s,1),Y}case"index":{let s=t.findIndex(o=>Ot(o)===Ot(r[0]??Y));if(s===-1)throw new _t("ValueError","is not in list");return s}case"count":return t.filter(s=>Ot(s)===Ot(r[0]??Y)).length;case"sort":return t.sort((s,o)=>typeof s=="number"&&typeof o=="number"?s-o:Te(s).localeCompare(Te(o))),Y;case"reverse":return t.reverse(),Y;case"copy":return[...t];case"clear":return t.splice(0),Y}if(yt(t))switch(e){case"keys":return[...t.data.keys()];case"values":return[...t.data.values()];case"items":return[...t.data.entries()].map(([s,o])=>[s,o]);case"get":return t.data.get(Te(r[0]??""))??r[1]??Y;case"update":{if(yt(r[0]??Y))for(let[s,o]of r[0].data)t.data.set(s,o);return Y}case"pop":{let s=Te(r[0]??""),o=t.data.get(s)??r[1]??Y;return t.data.delete(s),o}case"clear":return t.data.clear(),Y;case"copy":return bt([...t.data.entries()]);case"setdefault":{let s=Te(r[0]??"");return t.data.has(s)||t.data.set(s,r[1]??Y),t.data.get(s)??Y}}if(yt(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]??Y:Y;case"listdir":return[];case"path":return t}if(yt(t))switch(e){case"join":return r.map(Te).join("/").replace(/\/+/g,"/");case"exists":return!1;case"dirname":return Te(r[0]??"").split("/").slice(0,-1).join("/")||"/";case"basename":return Te(r[0]??"").split("/").pop()??"";case"abspath":return Te(r[0]??"");case"splitext":{let s=Te(r[0]??""),o=s.lastIndexOf(".");return o>0?[s.slice(0,o),s.slice(o)]:[s,""]}case"isfile":return!1;case"isdir":return!1}if(yt(t)&&t.data.has("version")&&t.data.get("version")===to&&e==="exit")throw new Wi(r[0]??0);if(yt(t)){let s={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 s){let o=s[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(yt(t)){if(e==="dumps"){let s=yt(r[1]??Y)?r[1]:void 0,o=s?s.data.get("indent"):void 0;return JSON.stringify(this.pyToJs(r[0]??Y),null,o)}if(e==="loads")return this.jsToPy(JSON.parse(Te(r[0]??"")))}if(Fi(t)){let s=t.attrs.get(e)??t.cls.methods.get(e)??Y;if(Pn(s)){let o=new Map(s.closure);return o.set("self",t),s.params.slice(1).forEach((a,c)=>o.set(a,r[c]??Y)),this.execBlock(s.body,o)}}throw new _t("AttributeError",`'${yr(t)}' object has no attribute '${e}'`)}pyStringFormat(t,e){let r=0;return t.replace(/%([diouxXeEfFgGcrs%])/g,(i,s)=>{if(s==="%")return"%";let o=e[r++];switch(s){case"d":case"i":return String(Math.trunc(o));case"f":return o.toFixed(6);case"s":return Te(o??Y);case"r":return Ot(o??Y);default:return String(o)}})}pyToJs(t){return qn(t)?null:yt(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?Y:typeof t=="boolean"||typeof t=="number"||typeof t=="string"?t:Array.isArray(t)?t.map(e=>this.jsToPy(e)):typeof t=="object"?bt(Object.entries(t).map(([e,r])=>[e,this.jsToPy(r)])):Y}callBuiltin(t,e,r){if(r.has(t)){let i=r.get(t)??Y;return Pn(i)?this.callFunc(i,e,r):Ac(i)?this.instantiate(i,e,r):i}switch(t){case"print":return this.output.push(e.map(Te).join(" ")+`
993
+ `.replace(/\\n/g,"")),Y;case"input":return this.output.push(Te(e[0]??"")),"";case"int":{if(e.length===0)return 0;let i=e[1]??10,s=parseInt(Te(e[0]??0),i);return Number.isNaN(s)?(()=>{throw new _t("ValueError","invalid literal for int()")})():s}case"float":{if(e.length===0)return 0;let i=parseFloat(Te(e[0]??0));return Number.isNaN(i)?(()=>{throw new _t("ValueError","could not convert to float")})():i}case"str":return e.length===0?"":Te(e[0]??Y);case"bool":return e.length===0?!1:hn(e[0]??Y);case"list":return e.length===0?[]:Tt(e[0]??[]);case"tuple":return e.length===0?[]:Tt(e[0]??[]);case"set":return e.length===0?[]:[...new Set(Tt(e[0]??[]).map(Ot))].map(i=>Tt(e[0]??[]).find(o=>Ot(o)===i)??Y);case"dict":return e.length===0?bt():yt(e[0]??Y)?e[0]:bt();case"bytes":return typeof e[0]=="string"?e[0]:Te(e[0]??"");case"bytearray":return e.length===0?"":Te(e[0]??"");case"type":return e.length===1?`<class '${yr(e[0]??Y)}'>`:Y;case"isinstance":return yr(e[0]??Y)===Te(e[1]??"");case"issubclass":return!1;case"callable":return Pn(e[0]??Y);case"hasattr":return yt(e[0]??Y)?e[0].data.has(Te(e[1]??"")):!1;case"getattr":return yt(e[0]??Y)?e[0].data.get(Te(e[1]??""))??e[2]??Y:e[2]??Y;case"setattr":return yt(e[0]??Y)&&e[0].data.set(Te(e[1]??""),e[2]??Y),Y;case"len":{let i=e[0]??Y;if(typeof i=="string"||Array.isArray(i))return i.length;if(yt(i))return i.data.size;if(ti(i))return Qd(i);throw new _t("TypeError",`object of type '${yr(i)}' has no len()`)}case"range":return e.length===1?gc(0,e[0]):e.length===2?gc(e[0],e[1]):gc(e[0],e[1],e[2]);case"enumerate":{let i=e[1]??0;return Tt(e[0]??[]).map((s,o)=>[o+i,s])}case"zip":{let i=e.map(Tt),s=Math.min(...i.map(o=>o.length));return Array.from({length:s},(o,a)=>i.map(c=>c[a]??Y))}case"map":{let i=e[0]??Y;return Tt(e[1]??[]).map(s=>Pn(i)?this.callFunc(i,[s],r):Y)}case"filter":{let i=e[0]??Y;return Tt(e[1]??[]).filter(s=>Pn(i)?hn(this.callFunc(i,[s],r)):hn(s))}case"reduce":{let i=e[0]??Y,s=Tt(e[1]??[]);if(s.length===0)return e[2]??Y;let o=e[2]!==void 0?e[2]:s[0];for(let a of e[2]!==void 0?s:s.slice(1))o=Pn(i)?this.callFunc(i,[o,a],r):Y;return o}case"sorted":{let i=[...Tt(e[0]??[])],s=e[1]??Y,o=yt(s)?s.data.get("key")??Y:s;return i.sort((a,c)=>{let l=Pn(o)?this.callFunc(o,[a],r):a,u=Pn(o)?this.callFunc(o,[c],r):c;return typeof l=="number"&&typeof u=="number"?l-u:Te(l).localeCompare(Te(u))}),i}case"reversed":return[...Tt(e[0]??[])].reverse();case"any":return Tt(e[0]??[]).some(hn);case"all":return Tt(e[0]??[]).every(hn);case"sum":return Tt(e[0]??[]).reduce((i,s)=>i+s,e[1]??0);case"max":return(e.length===1?Tt(e[0]??[]):e).reduce((s,o)=>s>=o?s:o);case"min":return(e.length===1?Tt(e[0]??[]):e).reduce((s,o)=>s<=o?s: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 i=e[0],s=e[1];return[Math.floor(i/s),i%s]}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 Te(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]:Te(e[0]??"").split("").reduce((i,s)=>i*31+s.charCodeAt(0)|0,0);case"open":throw new _t("PermissionError","open() not available in virtual runtime");case"repr":return Ot(e[0]??Y);case"iter":return e[0]??Y;case"next":return Array.isArray(e[0])&&e[0].length>0?e[0].shift():e[1]??(()=>{throw new _t("StopIteration","")})();case"vars":return bt([...r.entries()].map(([i,s])=>[i,s]));case"globals":return bt([...r.entries()].map(([i,s])=>[i,s]));case"locals":return bt([...r.entries()].map(([i,s])=>[i,s]));case"dir":{if(e.length===0)return[...r.keys()];let i=e[0]??Y;return typeof i=="string"?["upper","lower","strip","split","join","replace","find","format","encode","startswith","endswith","count","isdigit","isalpha","title","capitalize"]:Array.isArray(i)?["append","extend","insert","pop","remove","index","count","sort","reverse","copy","clear"]:yt(i)?["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 _t(t,Te(e[0]??""));case"exec":return this.execScript(Te(e[0]??""),r),Y;case"eval":return this.pyEval(Te(e[0]??""),r);default:throw new _t("NameError",`name '${t}' is not defined`)}}callFunc(t,e,r){let i=new Map(t.closure);t.params.forEach((s,o)=>{if(s.startsWith("*")){i.set(s.slice(1),e.slice(o));return}i.set(s,e[o]??Y)});try{return this.execBlock(t.body,i)}catch(s){if(s instanceof ei)return s.value;throw s}}instantiate(t,e,r){let i={__pytype__:"instance",cls:t,attrs:new Map};return t.methods.get("__init__")&&this.callMethod(i,"__init__",e,r),i}execScript(t,e){let r=t.split(`
994
+ `);this.execLines(r,0,e)}execLines(t,e,r){let i=e;for(;i<t.length;){let s=t[i];if(!s.trim()||s.trim().startsWith("#")){i++;continue}i=this.execStatement(t,i,r)}return i}execBlock(t,e){try{this.execLines(t,0,e)}catch(r){if(r instanceof ei)return r.value;throw r}return Y}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 i=[];for(let s=e;s<t.length;s++){let o=t[s];if(!o.trim()){i.push("");continue}if(this.getIndent(o)<=r)break;i.push(o.slice(r+4))}return i}execStatement(t,e,r){let i=t[e],s=i.trim(),o=this.getIndent(i);if(s==="pass")return e+1;if(s==="break")throw new Hi;if(s==="continue")throw new Qi;let a=s.match(/^return(?:\s+(.+))?$/);if(a)throw new ei(a[1]?this.pyEval(a[1],r):Y);let c=s.match(/^raise(?:\s+(.+))?$/);if(c){if(c[1]){let v=this.pyEval(c[1],r);throw new _t(typeof v=="string"?v:yr(v),Te(v))}throw new _t("RuntimeError","")}let l=s.match(/^assert\s+(.+?)(?:,\s*(.+))?$/);if(l){if(!hn(this.pyEval(l[1],r)))throw new _t("AssertionError",l[2]?Te(this.pyEval(l[2],r)):"");return e+1}let u=s.match(/^del\s+(.+)$/);if(u)return r.delete(u[1].trim()),e+1;let f=s.match(/^import\s+(\w+)(?:\s+as\s+(\w+))?$/);if(f){let[,v,b]=f,w=Hd[v];if(w){let k=w(this.cwd);this.modules.set(v,k),r.set(b??v,k)}return e+1}let h=s.match(/^from\s+(\w+)\s+import\s+(.+)$/);if(h){let[,v,b]=h,w=Hd[v];if(w){let k=w(this.cwd);if(b?.trim()==="*")for(let[N,R]of k.data)r.set(N,R);else for(let N of b.split(",").map(R=>R.trim()))r.set(N,k.data.get(N)??Y)}return e+1}let p=s.match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(p){let[,v,b]=p,w=b.split(",").map(R=>R.trim()).filter(Boolean),k=this.collectBlock(t,e+1,o),N={__pytype__:"func",name:v,params:w,body:k,closure:new Map(r)};return r.set(v,N),e+1+k.length}let y=s.match(/^class\s+(\w+)(?:\(([^)]*)\))?\s*:$/);if(y){let[,v,b]=y,w=b?b.split(",").map(ie=>ie.trim()):[],k=this.collectBlock(t,e+1,o),N={__pytype__:"class",name:v,methods:new Map,bases:w},R=0;for(;R<k.length;){let j=k[R].trim().match(/^def\s+(\w+)\s*\(([^)]*)\)\s*:$/);if(j){let[,X,re]=j,fe=re.split(",").map(B=>B.trim()).filter(Boolean),H=this.collectBlock(k,R+1,0);N.methods.set(X,{__pytype__:"func",name:X,params:fe,body:H,closure:new Map(r)}),R+=1+H.length}else R++}return r.set(v,N),e+1+k.length}if(s.startsWith("if ")&&s.endsWith(":")){let v=s.slice(3,-1).trim(),b=this.collectBlock(t,e+1,o),w=b.length+1;if(hn(this.pyEval(v,r))){this.execBlock(b,new Map(r).also?.(R=>{for(let[ie,j]of r)R.set(ie,j)})??r),this.runBlockInScope(b,r);let N=e+1+b.length;for(;N<t.length;){let R=t[N].trim();if(this.getIndent(t[N])<o||!R.startsWith("elif")&&!R.startsWith("else"))break;let ie=this.collectBlock(t,N+1,o);N+=1+ie.length}return N}let k=e+1+b.length;for(;k<t.length;){let N=t[k],R=N.trim();if(this.getIndent(N)!==o)break;let ie=R.match(/^elif\s+(.+):$/);if(ie){let j=this.collectBlock(t,k+1,o);if(hn(this.pyEval(ie[1],r))){for(this.runBlockInScope(j,r),k+=1+j.length;k<t.length;){let X=t[k].trim();if(this.getIndent(t[k])!==o||!X.startsWith("elif")&&!X.startsWith("else"))break;let re=this.collectBlock(t,k+1,o);k+=1+re.length}return k}k+=1+j.length;continue}if(R==="else:"){let j=this.collectBlock(t,k+1,o);return this.runBlockInScope(j,r),k+1+j.length}break}return k}let E=s.match(/^for\s+(.+?)\s+in\s+(.+?)\s*:$/);if(E){let[,v,b]=E,w=Tt(this.pyEval(b.trim(),r)),k=this.collectBlock(t,e+1,o),N=[],R=e+1+k.length;R<t.length&&t[R]?.trim()==="else:"&&(N=this.collectBlock(t,R+1,o),R+=1+N.length);let ie=!1;for(let j of w){if(v.includes(",")){let X=v.split(",").map(fe=>fe.trim()),re=Array.isArray(j)?j:[j];X.forEach((fe,H)=>r.set(fe,re[H]??Y))}else r.set(v.trim(),j);try{this.runBlockInScope(k,r)}catch(X){if(X instanceof Hi){ie=!0;break}if(X instanceof Qi)continue;throw X}}return!ie&&N.length&&this.runBlockInScope(N,r),R}let S=s.match(/^while\s+(.+?)\s*:$/);if(S){let v=S[1],b=this.collectBlock(t,e+1,o),w=0;for(;hn(this.pyEval(v,r))&&w++<1e5;)try{this.runBlockInScope(b,r)}catch(k){if(k instanceof Hi)break;if(k instanceof Qi)continue;throw k}return e+1+b.length}if(s==="try:"){let v=this.collectBlock(t,e+1,o),b=e+1+v.length,w=[],k=[],N=[];for(;b<t.length;){let ie=t[b],j=ie.trim();if(this.getIndent(ie)!==o)break;if(j.startsWith("except")){let X=j.match(/^except(?:\s+(\w+)(?:\s+as\s+(\w+))?)?\s*:$/),re=X?.[1]??null,fe=X?.[2],H=this.collectBlock(t,b+1,o);w.push({exc:re,body:H}),fe&&r.set(fe,""),b+=1+H.length}else if(j==="else:")N=this.collectBlock(t,b+1,o),b+=1+N.length;else if(j==="finally:")k=this.collectBlock(t,b+1,o),b+=1+k.length;else break}let R=null;try{this.runBlockInScope(v,r),N.length&&this.runBlockInScope(N,r)}catch(ie){if(ie instanceof _t){R=ie;let j=!1;for(let X of w)if(X.exc===null||X.exc===ie.type||X.exc==="Exception"){this.runBlockInScope(X.body,r),j=!0;break}if(!j)throw ie}else throw ie}finally{k.length&&this.runBlockInScope(k,r)}return b}let x=s.match(/^with\s+(.+?)\s+as\s+(\w+)\s*:$/);if(x){let v=this.collectBlock(t,e+1,o);return r.set(x[2],Y),this.runBlockInScope(v,r),e+1+v.length}let P=s.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(\+=|-=|\*=|\/\/=|\/=|%=|\*\*=|&=|\|=)\s*(.+)$/);if(P){let[,v,b,w]=P,k=r.get(v)??0,N=this.pyEval(w,r),R;switch(b){case"+=":R=typeof k=="string"?k+Te(N):k+N;break;case"-=":R=k-N;break;case"*=":R=k*N;break;case"/=":R=k/N;break;case"//=":R=Math.floor(k/N);break;case"%=":R=k%N;break;case"**=":R=k**N;break;default:R=N}return r.set(v,R),e+1}let q=s.match(/^([A-Za-z_][A-Za-z0-9_]*)\[(.+)\]\s*=\s*(.+)$/);if(q){let[,v,b,w]=q,k=r.get(v)??Y,N=this.pyEval(w,r)??Y,R=this.pyEval(b,r)??Y;return Array.isArray(k)?k[R]=N:yt(k)&&k.data.set(Te(R),N),e+1}let C=s.match(/^([A-Za-z_][A-Za-z0-9_.]+)\s*=\s*(.+)$/);if(C){let v=C[1].lastIndexOf(".");if(v!==-1){let b=C[1].slice(0,v),w=C[1].slice(v+1),k=this.pyEval(C[2],r),N=this.pyEval(b,r);return yt(N)?N.data.set(w,k):Fi(N)&&N.attrs.set(w,k),e+1}}let $=s.match(/^([A-Za-z_][A-Za-z0-9_,\s]*),\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.+)$/);if($){let v=this.pyEval($[3],r),b=s.split("=")[0].split(",").map(k=>k.trim()),w=Tt(v);return b.forEach((k,N)=>r.set(k,w[N]??Y)),e+1}let F=s.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(?::[^=]+)?\s*=\s*(.+)$/);if(F){let[,v,b]=F;return r.set(v,this.pyEval(b,r)),e+1}try{this.pyEval(s,r)}catch(v){if(v instanceof _t||v instanceof Wi)throw v}return e+1}runBlockInScope(t,e){this.execLines(t,0,e)}run(t){let e=fy(this.cwd);try{this.execScript(t,e)}catch(r){return r instanceof Wi?{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:r.code}:r instanceof _t?(this.stderr.push(r.toString()),{stdout:this.getOutput(),stderr:this.getStderr(),exitCode:1}):r instanceof ei?{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}}},Wd={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
995
995
  Hint: install it with: apt install python3
996
- `,exitCode:127};if(ae(n,["--version","-V"]))return{stdout:`${oy}
997
- `,exitCode:0};if(ae(n,["--version-full"]))return{stdout:`${Zs}
998
- `,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
999
- `,exitCode:1};let o=i.replace(/\\n/g,`
1000
- `).replace(/\\t/g," "),a=new eo(e),{stdout:c,stderr:l,exitCode:u}=a.run(o);return{stdout:c||void 0,stderr:l||void 0,exitCode:u}}let s=n.find(i=>!i.startsWith("-"));if(s){let i=he(e,s);if(!t.vfs.exists(i))return{stderr:`python3: can't open file '${s}': [Errno 2] No such file or directory
1001
- `,exitCode:2};let o=t.vfs.readFile(i),a=new eo(e),{stdout:c,stderr:l,exitCode:u}=a.run(o);return{stdout:c||void 0,stderr:l||void 0,exitCode:u}}return{stdout:`${Zs}
996
+ `,exitCode:127};if(ae(n,["--version","-V"]))return{stdout:`${ly}
997
+ `,exitCode:0};if(ae(n,["--version-full"]))return{stdout:`${to}
998
+ `,exitCode:0};let r=n.indexOf("-c");if(r!==-1){let s=n[r+1];if(!s)return{stderr:`python3: -c requires a code argument
999
+ `,exitCode:1};let o=s.replace(/\\n/g,`
1000
+ `).replace(/\\t/g," "),a=new no(e),{stdout:c,stderr:l,exitCode:u}=a.run(o);return{stdout:c||void 0,stderr:l||void 0,exitCode:u}}let i=n.find(s=>!s.startsWith("-"));if(i){let s=he(e,i);if(!t.vfs.exists(s))return{stderr:`python3: can't open file '${i}': [Errno 2] No such file or directory
1001
+ `,exitCode:2};let o=t.vfs.readFile(s),a=new no(e),{stdout:c,stderr:l,exitCode:u}=a.run(o);return{stdout:c||void 0,stderr:l||void 0,exitCode:u}}return{stdout:`${to}
1002
1002
  Type "help", "copyright", "credits" or "license" for more information.
1003
- >>> `,exitCode:0}}};var Qd={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(`
1004
- `)[0]??"",o=ae(n,["-r"])?i:i.replace(/\\(?:\r?\n|.)/g,a=>a[1]===`
1005
- `||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 Wd={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=ae(r,["-r","-rf","-fr"]),i=[];for(let o=0;;o+=1){let a=rr(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=he(e,o);Fe(n,a,"rm"),t.vfs.remove(a,{recursive:s})}return{exitCode:0}}};var qd={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=ae(r,["-i"]),o=an(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=he(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[,,u,f,h]=l,p=(h??"").includes("i")?"gi":(h??"").includes("g")?"g":"",y;try{y=new RegExp(u,p||"")}catch{return{stderr:`sed: invalid regex: ${u}`,exitCode:1}}let E=((h??"").includes("g")||p.includes("g"),c.replace(y,f??""));if(i&&a){let S=he(e,a);return t.writeFileAsUser(n,S,E),{exitCode:0}}return{stdout:E,exitCode:0}}};var Kd={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(`
1006
- `),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 Ac(n,t,e,r){return Vs(n,t,e,s=>wt(s,r.authUser,r.hostname,r.mode,r.cwd,r.shell,void 0,r.env).then(i=>i.stdout??""))}function ir(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=[],u=[],f="then",h="";for(e++;e<n.length&&n[e]?.trim()!=="fi";){let p=n[e].trim();p.startsWith("elif ")?(f="elif",h=p.replace(/^elif\s+/,"").replace(/;\s*then\s*$/,"").trim(),l.push({cond:h,body:[]})):p==="else"?f="else":p!=="then"&&(f==="then"?c.push(p):f==="elif"&&l.length>0?l[l.length-1].body.push(p):u.push(p)),e++}t.push({type:"if",cond:a,then_:c,elif:l,else_:u})}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 gc(n,t){let e=await Ac(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,u]=o,f=he(t.cwd,u);if(l==="f")return t.shell.vfs.exists(f)&&t.shell.vfs.stat(f).type==="file";if(l==="d")return t.shell.vfs.exists(f)&&t.shell.vfs.stat(f).type==="directory";if(l==="e")return t.shell.vfs.exists(f);if(l==="z")return(u??"").length===0;if(l==="n")return(u??"").length>0}let a=i.match(/^"?([^"]*)"?\s*(==|!=|=|<|>)\s*"?([^"]*)"?$/);if(a){let[,l,u,f]=a;if(u==="=="||u==="=")return l===f;if(u==="!=")return l!==f}let c=i.match(/^(\S+)\s+(-eq|-ne|-lt|-le|-gt|-ge)\s+(\S+)$/);if(c){let[,l,u,f]=c,h=Number(l),p=Number(f);if(u==="-eq")return h===p;if(u==="-ne")return h!==p;if(u==="-lt")return h<p;if(u==="-le")return h<=p;if(u==="-gt")return h>p;if(u==="-ge")return h>=p}}return((await wt(e,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env)).exitCode??0)===0}async function sr(n,t){let e={exitCode:0},r="";for(let s of n)if(s.type==="cmd"){let i=await Ac(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(u=>o.test(u))){for(let u of a){let f=u.match(o);t.env.vars[f[1]]=f[2]}t.env.lastExitCode=0;continue}let c=await(async()=>{let l=i.trim().split(/\s+/)[0]??"",u=t.env.vars[`__func_${l}`];if(u){let f=i.trim().split(/\s+/).slice(1),h={...t.env.vars};f.forEach((E,S)=>{t.env.vars[String(S+1)]=E}),t.env.vars[0]=l;let p=u.split(`
1007
- `),y=await sr(ir(p),t);for(let E=1;E<=f.length;E++)delete t.env.vars[String(E)];return Object.assign(t.env.vars,{...h,...t.env.vars}),y}return wt(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}
1008
- `),c.stderr)return{...c,stdout:r.trim()};e=c}else if(s.type==="if"){let i=!1;if(await gc(s.cond,t)){let o=await sr(ir(s.then_),t);o.stdout&&(r+=`${o.stdout}
1009
- `),i=!0}else{for(let o of s.elif)if(await gc(o.cond,t)){let a=await sr(ir(o.body),t);a.stdout&&(r+=`${a.stdout}
1010
- `),i=!0;break}if(!i&&s.else_.length>0){let o=await sr(ir(s.else_),t);o.stdout&&(r+=`${o.stdout}
1011
- `)}}}else if(s.type==="func")t.env.vars[`__func_${s.name}`]=s.body.join(`
1012
- `);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),u={"+":c+l,"-":c-l,"*":c*l,"/":Math.floor(c/l)};t.env.vars[a[1]]=String(u[a[2]]??c)}else{let c=uc(i,t.env.vars);Number.isNaN(c)||(t.env.lastExitCode=c===0?1:0)}}}else if(s.type==="for"){let o=(await Ac(s.list,t.env.vars,t.env.lastExitCode,t)).trim().split(/\s+/).flatMap(Ks);for(let a of o){t.env.vars[s.var]=a;let c=await sr(ir(s.body),t);if(c.stdout&&(r+=`${c.stdout}
1013
- `),c.closeSession)return c}}else if(s.type==="while"){let i=0;for(;i<1e3&&await gc(s.cond,t);){let o=await sr(ir(s.body),t);if(o.stdout&&(r+=`${o.stdout}
1014
- `),o.closeSession)return o;i++}}return{...e,stdout:r.trim()||e.stdout}}function Vd(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===`
1015
- `)){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 zd={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(ae(t,"-c")){let i=t[t.indexOf("-c")+1]??"";if(!i)return{stderr:"sh: -c requires a script",exitCode:1};let o=Vd(i),a=ir(o);return sr(a,n)}let s=t[0];if(s){let i=he(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=Vd(o),c=ir(a);return sr(c,n)}return{stderr:"sh: invalid usage. Use: sh -c 'cmd' or sh <file>",exitCode:1}}};var Gd={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}}},Yd={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}}},jd={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 Xd={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 Jd={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=ae(r,["-r"]),o=ae(r,["-n"]),a=ae(r,["-u"]),c=r.filter(y=>!y.startsWith("-")),f=[...(c.length>0?c.map(y=>{try{return Fe(n,he(e,y),"sort"),t.vfs.readFile(he(e,y))}catch{return""}}).join(`
1016
- `):s??"").split(`
1017
- `).filter(Boolean)].sort((y,E)=>o?Number(y)-Number(E):y.localeCompare(E)),h=i?f.reverse():f;return{stdout:(a?[...new Set(h)]:h).join(`
1018
- `),exitCode:0}}};var Zd={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=he(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 u of c.split(`
1019
- `)){let f=u.trim();if(!f||f.startsWith("#"))continue;let h=await wt(f,t,e,"shell",r,s,void 0,i);if(l=h.exitCode??0,h.closeSession||h.switchUser)return h}return{exitCode:l}}};var eh={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,u=e.filter((f,h)=>h!==a&&h!==a+1).filter(f=>f!=="-"&&f!=="-l"&&f!=="--login").find(f=>!f.startsWith("-"))??"root";return t.users.listUsers().includes(u)?n==="root"?c?wt(c,u,r,s,o?`/home/${u}`:i,t):{switchUser:u,nextCwd:o?`/home/${u}`:void 0,exitCode:0}:t.users.isSudoer(n)?{sudoChallenge:{username:u,targetUser:u,commandLine:c??null,loginShell:o,prompt:"Password: "},exitCode:0}:{stderr:`su: permission denied
1003
+ >>> `,exitCode:0}}};var qd={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"),i=n.filter((a,c)=>a!=="-r"&&a!=="-p"&&n[c-1]!=="-p"),s=(t??"").split(`
1004
+ `)[0]??"",o=ae(n,["-r"])?s:s.replace(/\\(?:\r?\n|.)/g,a=>a[1]===`
1005
+ `||a[1]==="\r"?"":a[1]);if(!e)return{exitCode:0};if(i.length===0)e.vars.REPLY=o;else if(i.length===1)e.vars[i[0]]=o;else{let a=o.split(/\s+/);for(let c=0;c<i.length;c++)e.vars[i[c]]=c<i.length-1?a[c]??"":a.slice(c).join(" ")}return{exitCode:0}}};var Kd={name:"rm",description:"Remove files or directories",category:"files",params:["[-r|-rf] <path>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"rm: missing operand",exitCode:1};let i=ae(r,["-r","-rf","-fr"]),s=[];for(let o=0;;o+=1){let a=rr(r,o,{flags:["-r","-rf","-fr"]});if(!a)break;s.push(a)}if(s.length===0)return{stderr:"rm: missing operand",exitCode:1};for(let o of s){let a=he(e,o);Fe(n,a,"rm"),t.vfs.remove(a,{recursive:i})}return{exitCode:0}}};var Vd={name:"sed",description:"Stream editor for filtering and transforming text",category:"text",params:["-e <expr> [file]","s/pattern/replace/[g]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=ae(r,["-i"]),o=an(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=i??"";if(a){let S=he(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[,,u,f,h]=l,p=(h??"").includes("i")?"gi":(h??"").includes("g")?"g":"",y;try{y=new RegExp(u,p||"")}catch{return{stderr:`sed: invalid regex: ${u}`,exitCode:1}}let E=((h??"").includes("g")||p.includes("g"),c.replace(y,f??""));if(s&&a){let S=he(e,a);return t.writeFileAsUser(n,S,E),{exitCode:0}}return{stdout:E,exitCode:0}}};var zd={name:"set",description:"Display or set shell variables",category:"shell",params:["[VAR=value]"],run:({args:n,env:t})=>{if(n.length===0)return{stdout:Object.entries(t.vars).map(([r,i])=>`${r}=${i}`).join(`
1006
+ `),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 Ec(n,t,e,r){return zs(n,t,e,i=>wt(i,r.authUser,r.hostname,r.mode,r.cwd,r.shell,void 0,r.env).then(s=>s.stdout??""))}function sr(n){let t=[],e=0;for(;e<n.length;){let r=n[e].trim();if(!r||r.startsWith("#")){e++;continue}let i=r.match(/^(?:function\s+)?(\w+)\s*\(\s*\)\s*\{(.+)\}\s*$/),s=i??(r.match(/^(?:function\s+)?(\w+)\s*\(\s*\)\s*\{?\s*$/)||r.match(/^function\s+(\w+)\s*\{?\s*$/));if(s){let a=s[1],c=[];if(i){c.push(...i[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=[],u=[],f="then",h="";for(e++;e<n.length&&n[e]?.trim()!=="fi";){let p=n[e].trim();p.startsWith("elif ")?(f="elif",h=p.replace(/^elif\s+/,"").replace(/;\s*then\s*$/,"").trim(),l.push({cond:h,body:[]})):p==="else"?f="else":p!=="then"&&(f==="then"?c.push(p):f==="elif"&&l.length>0?l[l.length-1].body.push(p):u.push(p)),e++}t.push({type:"if",cond:a,then_:c,elif:l,else_:u})}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 yc(n,t){let e=await Ec(n,t.env.vars,t.env.lastExitCode,t),r=e.match(/^\[?\s*(.+?)\s*\]?$/);if(r){let s=r[1],o=s.match(/^-([fdeznr])\s+(.+)$/);if(o){let[,l,u]=o,f=he(t.cwd,u);if(l==="f")return t.shell.vfs.exists(f)&&t.shell.vfs.stat(f).type==="file";if(l==="d")return t.shell.vfs.exists(f)&&t.shell.vfs.stat(f).type==="directory";if(l==="e")return t.shell.vfs.exists(f);if(l==="z")return(u??"").length===0;if(l==="n")return(u??"").length>0}let a=s.match(/^"?([^"]*)"?\s*(==|!=|=|<|>)\s*"?([^"]*)"?$/);if(a){let[,l,u,f]=a;if(u==="=="||u==="=")return l===f;if(u==="!=")return l!==f}let c=s.match(/^(\S+)\s+(-eq|-ne|-lt|-le|-gt|-ge)\s+(\S+)$/);if(c){let[,l,u,f]=c,h=Number(l),p=Number(f);if(u==="-eq")return h===p;if(u==="-ne")return h!==p;if(u==="-lt")return h<p;if(u==="-le")return h<=p;if(u==="-gt")return h>p;if(u==="-ge")return h>=p}}return((await wt(e,t.authUser,t.hostname,t.mode,t.cwd,t.shell,void 0,t.env)).exitCode??0)===0}async function or(n,t){let e={exitCode:0},r="";for(let i of n)if(i.type==="cmd"){let s=await Ec(i.line,t.env.vars,t.env.lastExitCode,t),o=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)/,a=s.trim().split(/\s+/);if(a.length>0&&o.test(a[0])&&a.every(u=>o.test(u))){for(let u of a){let f=u.match(o);t.env.vars[f[1]]=f[2]}t.env.lastExitCode=0;continue}let c=await(async()=>{let l=s.trim().split(/\s+/)[0]??"",u=t.env.vars[`__func_${l}`];if(u){let f=s.trim().split(/\s+/).slice(1),h={...t.env.vars};f.forEach((E,S)=>{t.env.vars[String(S+1)]=E}),t.env.vars[0]=l;let p=u.split(`
1007
+ `),y=await or(sr(p),t);for(let E=1;E<=f.length;E++)delete t.env.vars[String(E)];return Object.assign(t.env.vars,{...h,...t.env.vars}),y}return wt(s,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}
1008
+ `),c.stderr)return{...c,stdout:r.trim()};e=c}else if(i.type==="if"){let s=!1;if(await yc(i.cond,t)){let o=await or(sr(i.then_),t);o.stdout&&(r+=`${o.stdout}
1009
+ `),s=!0}else{for(let o of i.elif)if(await yc(o.cond,t)){let a=await or(sr(o.body),t);a.stdout&&(r+=`${a.stdout}
1010
+ `),s=!0;break}if(!s&&i.else_.length>0){let o=await or(sr(i.else_),t);o.stdout&&(r+=`${o.stdout}
1011
+ `)}}}else if(i.type==="func")t.env.vars[`__func_${i.name}`]=i.body.join(`
1012
+ `);else if(i.type==="arith"){let s=i.expr.trim(),o=s.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=s.match(/^(\w+)\s*([+\-*/])=\s*(.+)$/);if(a){let c=parseInt(t.env.vars[a[1]]??"0",10),l=parseInt(a[3],10),u={"+":c+l,"-":c-l,"*":c*l,"/":Math.floor(c/l)};t.env.vars[a[1]]=String(u[a[2]]??c)}else{let c=dc(s,t.env.vars);Number.isNaN(c)||(t.env.lastExitCode=c===0?1:0)}}}else if(i.type==="for"){let o=(await Ec(i.list,t.env.vars,t.env.lastExitCode,t)).trim().split(/\s+/).flatMap(Vs);for(let a of o){t.env.vars[i.var]=a;let c=await or(sr(i.body),t);if(c.stdout&&(r+=`${c.stdout}
1013
+ `),c.closeSession)return c}}else if(i.type==="while"){let s=0;for(;s<1e3&&await yc(i.cond,t);){let o=await or(sr(i.body),t);if(o.stdout&&(r+=`${o.stdout}
1014
+ `),o.closeSession)return o;s++}}return{...e,stdout:r.trim()||e.stdout}}function Gd(n){let t=[],e="",r=0,i=!1,s=!1,o=0;for(;o<n.length;){let c=n[o];if(!i&&!s){if(c==="'"){i=!0,e+=c,o++;continue}if(c==='"'){s=!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===`
1015
+ `)){let l=e.trim();l&&!l.startsWith("#")&&t.push(l),e="",o++;continue}}else i&&c==="'"?i=!1:s&&c==='"'&&(s=!1);e+=c,o++}let a=e.trim();return a&&!a.startsWith("#")&&t.push(a),t}var Yd={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(ae(t,"-c")){let s=t[t.indexOf("-c")+1]??"";if(!s)return{stderr:"sh: -c requires a script",exitCode:1};let o=Gd(s),a=sr(o);return or(a,n)}let i=t[0];if(i){let s=he(r,i);if(!e.vfs.exists(s))return{stderr:`sh: ${i}: No such file or directory`,exitCode:1};let o=e.vfs.readFile(s),a=Gd(o),c=sr(a);return or(c,n)}return{stderr:"sh: invalid usage. Use: sh -c 'cmd' or sh <file>",exitCode:1}}};var jd={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 i=r.slice(e);for(let s=1;s<=9;s++)t.vars[String(s)]=i[s-1]??"";return{exitCode:0}}},Xd={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 i of r)t.vars[`__trap_${i.toUpperCase()}`]=e;return{exitCode:0}}},Jd={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 Zd={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 eh={name:"sort",description:"Sort lines of text",category:"text",params:["[-r] [-n] [-u] [-k <col>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=ae(r,["-r"]),o=ae(r,["-n"]),a=ae(r,["-u"]),c=r.filter(y=>!y.startsWith("-")),f=[...(c.length>0?c.map(y=>{try{return Fe(n,he(e,y),"sort"),t.vfs.readFile(he(e,y))}catch{return""}}).join(`
1016
+ `):i??"").split(`
1017
+ `).filter(Boolean)].sort((y,E)=>o?Number(y)-Number(E):y.localeCompare(E)),h=s?f.reverse():f;return{stdout:(a?[...new Set(h)]:h).join(`
1018
+ `),exitCode:0}}};var th={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:i,env:s})=>{let o=n[0];if(!o)return{stderr:"source: missing filename",exitCode:1};let a=he(r,o);if(!i.vfs.exists(a))return{stderr:`source: ${o}: No such file or directory`,exitCode:1};let c=i.vfs.readFile(a),l=0;for(let u of c.split(`
1019
+ `)){let f=u.trim();if(!f||f.startsWith("#"))continue;let h=await wt(f,t,e,"shell",r,i,void 0,s);if(l=h.exitCode??0,h.closeSession||h.switchUser)return h}return{exitCode:l}}};var nh={name:"su",description:"Switch user",category:"users",params:["[-] [-c <cmd>] [username]"],run:async({authUser:n,shell:t,args:e,hostname:r,mode:i,cwd:s})=>{let o=e.includes("-")||e.includes("-l")||e.includes("--login"),a=e.indexOf("-c"),c=a!==-1?e[a+1]:void 0,u=e.filter((f,h)=>h!==a&&h!==a+1).filter(f=>f!=="-"&&f!=="-l"&&f!=="--login").find(f=>!f.startsWith("-"))??"root";return t.users.listUsers().includes(u)?n==="root"?c?wt(c,u,r,i,o?`/home/${u}`:s,t):{switchUser:u,nextCwd:o?`/home/${u}`:void 0,exitCode:0}:t.users.isSudoer(n)?{sudoChallenge:{username:u,targetUser:u,commandLine:c??null,loginShell:o,prompt:"Password: "},exitCode:0}:{stderr:`su: permission denied
1020
1020
  `,exitCode:1}:{stderr:`su: user '${u}' does not exist
1021
- `,exitCode:1}}};function py(n){let{flags:t,flagsWithValues:e,positionals:r}=en(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 th={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}=py(i);if(n!=="root"&&!s.users.isSudoer(n))return{stderr:"sudo: permission denied",exitCode:1};let l=o||"root",u=`[sudo] password for ${n}: `;return n==="root"?!c&&a?{switchUser:l,nextCwd:`/home/${l}`,exitCode:0}:c?wt(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:u},exitCode:0}}};var nh={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=an(r,["-n"]),o=r.find(f=>/^-\d+$/.test(f)),a=typeof i=="string"?parseInt(i,10):o?parseInt(o.slice(1),10):10,c=r.filter(f=>!f.startsWith("-")&&f!==i&&f!==String(a)),l=f=>{let h=f.split(`
1021
+ `,exitCode:1}}};function Ay(n){let{flags:t,flagsWithValues:e,positionals:r}=en(n,{flags:["-i","-S"],flagsWithValue:["-u","--user"]}),i=t.has("-i"),s=e.get("-u")||e.get("--user")||"root",o=r.length>0?r.join(" "):null;return{targetUser:s,loginShell:i,commandLine:o}}var rh={name:"sudo",description:"Execute as superuser",category:"users",params:["<command...>"],run:async({authUser:n,hostname:t,mode:e,cwd:r,shell:i,args:s})=>{let{targetUser:o,loginShell:a,commandLine:c}=Ay(s);if(n!=="root"&&!i.users.isSudoer(n))return{stderr:"sudo: permission denied",exitCode:1};let l=o||"root",u=`[sudo] password for ${n}: `;return n==="root"?!c&&a?{switchUser:l,nextCwd:`/home/${l}`,exitCode:0}:c?wt(c,l,t,e,a?`/home/${l}`:r,i):{stderr:"sudo: missing command",exitCode:1}:{sudoChallenge:{username:n,targetUser:l,commandLine:c,loginShell:a,prompt:u},exitCode:0}}};var ih={name:"tail",description:"Output last lines",category:"text",params:["[-n <lines>] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=an(r,["-n"]),o=r.find(f=>/^-\d+$/.test(f)),a=typeof s=="string"?parseInt(s,10):o?parseInt(o.slice(1),10):10,c=r.filter(f=>!f.startsWith("-")&&f!==s&&f!==String(a)),l=f=>{let h=f.split(`
1022
1022
  `),p=f.endsWith(`
1023
1023
  `),y=p?h.slice(0,-1):h;return y.slice(Math.max(0,y.length-a)).join(`
1024
1024
  `)+(p?`
1025
- `:"")};if(c.length===0)return{stdout:l(s??""),exitCode:0};let u=[];for(let f of c){let h=he(e,f);try{Fe(n,h,"tail"),u.push(l(t.vfs.readFile(h)))}catch{return{stderr:`tail: ${f}: No such file or directory`,exitCode:1}}}return{stdout:u.join(`
1026
- `),exitCode:0}}};var rh={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"),u=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
1025
+ `:"")};if(c.length===0)return{stdout:l(i??""),exitCode:0};let u=[];for(let f of c){let h=he(e,f);try{Fe(n,h,"tail"),u.push(l(t.vfs.readFile(h)))}catch{return{stderr:`tail: ${f}: No such file or directory`,exitCode:1}}}return{stdout:u.join(`
1026
+ `),exitCode:0}}};var sh={name:"tar",description:"Archive utility",category:"archive",params:["[-czf|-xzf|-tf] <archive> [files...]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=[],s=!1;for(let h of r)if(/^-[a-zA-Z]{2,}$/.test(h))for(let p of h.slice(1))i.push(`-${p}`);else if(!s&&/^[cxtdru]{1,}[a-zA-Z]*$/.test(h)&&!h.includes("/")&&!h.startsWith("-")){s=!0;for(let p of h)i.push(`-${p}`)}else i.push(h);let o=i.includes("-c"),a=i.includes("-x"),c=i.includes("-t"),l=i.indexOf("-f"),u=l!==-1?i[l+1]:i.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
1027
1027
  `,exitCode:1};if(!u)return{stderr:`tar: no archive specified
1028
- `,exitCode:1};let f=he(e,u);if(o){let h=new Set;l!==-1&&h.add(l+1);let p=s.filter((E,S)=>!E.startsWith("-")&&E!==u&&!h.has(S)),y={};for(let E of p){let S=he(e,E);try{if(t.vfs.stat(S).type==="file")y[E]=t.vfs.readFile(S);else{let P=(q,C)=>{for(let $ of t.vfs.list(q)){let F=`${q}/${$}`,v=`${C}/${$}`;t.vfs.stat(F).type==="file"?y[v]=t.vfs.readFile(F):P(F,v)}};P(S,E)}}catch{return{stderr:`tar: ${E}: No such file or directory`,exitCode:1}}}return t.writeFileAsUser(n,f,JSON.stringify(y)),{exitCode:0}}if(c||a){let h;try{h=JSON.parse(t.vfs.readFile(f))}catch{return{stderr:`tar: ${u}: cannot open archive`,exitCode:1}}if(c)return{stdout:Object.keys(h).join(`
1029
- `),exitCode:0};for(let[p,y]of Object.entries(h))t.writeFileAsUser(n,he(e,p),y);return{exitCode:0}}return{stderr:"tar: must specify -c, -x, or -t",exitCode:1}}};var ih={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=ae(r,["-a"]),o=r.filter(c=>!c.startsWith("-")),a=s??"";for(let c of o){let l=he(e,c);if(i){let u=(()=>{try{return t.vfs.readFile(l)}catch{return""}})();t.writeFileAsUser(n,l,u+a)}else t.writeFileAsUser(n,l,a)}return{stdout:a,exitCode:0}}};function ti(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!ti(n.slice(1),t,e);let r=n.indexOf("-a");if(r!==-1)return ti(n.slice(0,r),t,e)&&ti(n.slice(r+1),t,e);let s=n.indexOf("-o");if(s!==-1)return ti(n.slice(0,s),t,e)||ti(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 sh={name:"test",aliases:["["],description:"Evaluate conditional expression",category:"shell",params:["<expression>"],run:({args:n,shell:t,cwd:e})=>{try{return{exitCode:ti([...n],t,e)?0:1}}catch{return{stderr:"test: malformed expression",exitCode:2}}}};var oh={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=he(e,s);Fe(n,i,"touch"),t.vfs.exists(i)||t.writeFileAsUser(n,i,"")}return{exitCode:0}}};function my(n){return n.replace(/\\n/g,`
1030
- `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\")}function ah(n){let t=[],e=my(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 ch={name:"tr",description:"Translate or delete characters",category:"text",params:["[-d] [-s] <set1> [set2]"],run:({args:n,stdin:t})=>{let e=ae(n,["-d"]),r=ae(n,["-s"]),s=n.filter(c=>!c.startsWith("-")),i=ah(s[0]??""),o=ah(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,u)=>c.has(u)?u:l)}return{stdout:a,exitCode:0}}};var lh={name:"tree",description:"Display directory tree",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let s=he(e,rr(r,0)??e);return Fe(n,s,"tree"),{stdout:t.vfs.tree(s),exitCode:0}}};var uh={name:"true",description:"Return success exit code",category:"shell",params:[],run:()=>({exitCode:0})},fh={name:"false",description:"Return failure exit code",category:"shell",params:[],run:()=>({exitCode:1})};var dh={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(wn(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(`
1031
- `),exitCode:i}}};var hh={name:"uname",description:"Print system information",category:"system",params:["[-a] [-s] [-r] [-m]"],run:({shell:n,args:t})=>{let e=ae(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}:ae(t,["-r"])?{stdout:s,exitCode:0}:ae(t,["-m"])?{stdout:i,exitCode:0}:{stdout:r,exitCode:0}}};var ph={name:"uniq",description:"Report or filter out repeated lines",category:"text",params:["[-c] [-d] [-u] [file]"],run:({args:n,stdin:t})=>{let e=ae(n,["-c"]),r=ae(n,["-d"]),s=ae(n,["-u"]),i=(t??"").split(`
1032
- `),o=[],a=0;for(;a<i.length;){let c=a;for(;c<i.length&&i[c]===i[a];)c++;let l=c-a,u=i[a];if(r&&l===1){a=c;continue}if(s&&l>1){a=c;continue}o.push(e?`${String(l).padStart(4)} ${u}`:u),a=c}return{stdout:o.join(`
1033
- `),exitCode:0}}};var mh={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 gh={name:"uptime",description:"Tell how long the system has been running",category:"system",params:["[-p] [-s]"],run:({args:n,shell:t})=>{let e=ae(n,["-p"]),r=ae(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")}`,u=t.users.listActiveSessions().length,f=(Math.random()*.5).toFixed(2);return{stdout:` ${c} up ${l}, ${u} user${u!==1?"s":""}, load average: ${f}, ${f}, ${f}`,exitCode:0}}};var Ah={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=ae(r,["-l"]),o=ae(r,["-w"]),a=ae(r,["-c"]),c=!i&&!o&&!a,l=r.filter(h=>!h.startsWith("-")),u=(h,p)=>{let y=h.length===0?0:h.trim().split(`
1034
- `).length,E=h.trim().split(/\s+/).filter(Boolean).length,S=Buffer.byteLength(h,"utf8"),x=[];return(c||i)&&x.push(String(y).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:u(s??"",""),exitCode:0};let f=[];for(let h of l){let p=he(e,h);try{Fe(n,p,"wc");let y=t.vfs.readFile(p);f.push(u(y,h))}catch{return{stderr:`wc: ${h}: No such file or directory`,exitCode:1}}}return{stdout:f.join(`
1035
- `),exitCode:0}}};var yh={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}=en(e,{flagsWithValue:["-O","--output-document","-o","--output-file","-P","--directory-prefix","--tries","--timeout"]});if(ae(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(`
1036
- `),exitCode:0};if(ae(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
1028
+ `,exitCode:1};let f=he(e,u);if(o){let h=new Set;l!==-1&&h.add(l+1);let p=i.filter((E,S)=>!E.startsWith("-")&&E!==u&&!h.has(S)),y={};for(let E of p){let S=he(e,E);try{if(t.vfs.stat(S).type==="file")y[E]=t.vfs.readFile(S);else{let P=(q,C)=>{for(let $ of t.vfs.list(q)){let F=`${q}/${$}`,v=`${C}/${$}`;t.vfs.stat(F).type==="file"?y[v]=t.vfs.readFile(F):P(F,v)}};P(S,E)}}catch{return{stderr:`tar: ${E}: No such file or directory`,exitCode:1}}}return t.writeFileAsUser(n,f,JSON.stringify(y)),{exitCode:0}}if(c||a){let h;try{h=JSON.parse(t.vfs.readFile(f))}catch{return{stderr:`tar: ${u}: cannot open archive`,exitCode:1}}if(c)return{stdout:Object.keys(h).join(`
1029
+ `),exitCode:0};for(let[p,y]of Object.entries(h))t.writeFileAsUser(n,he(e,p),y);return{exitCode:0}}return{stderr:"tar: must specify -c, -x, or -t",exitCode:1}}};var oh={name:"tee",description:"Read stdin, write to stdout and files",category:"text",params:["[-a] <file...>"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=ae(r,["-a"]),o=r.filter(c=>!c.startsWith("-")),a=i??"";for(let c of o){let l=he(e,c);if(s){let u=(()=>{try{return t.vfs.readFile(l)}catch{return""}})();t.writeFileAsUser(n,l,u+a)}else t.writeFileAsUser(n,l,a)}return{stdout:a,exitCode:0}}};function ni(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!ni(n.slice(1),t,e);let r=n.indexOf("-a");if(r!==-1)return ni(n.slice(0,r),t,e)&&ni(n.slice(r+1),t,e);let i=n.indexOf("-o");if(i!==-1)return ni(n.slice(0,i),t,e)||ni(n.slice(i+1),t,e);if(n.length===2){let[s,o=""]=n,c=(l=>l.startsWith("/")?l:`${e}/${l}`.replace(/\/+/g,"/"))(o);switch(s){case"-e":return t.vfs.exists(c);case"-f":return t.vfs.exists(c)&&t.vfs.stat(c).type==="file";case"-d":return t.vfs.exists(c)&&t.vfs.stat(c).type==="directory";case"-r":return t.vfs.exists(c);case"-w":return t.vfs.exists(c);case"-x":return t.vfs.exists(c)&&!!(t.vfs.stat(c).mode&73);case"-s":return t.vfs.exists(c)&&t.vfs.stat(c).type==="file"&&t.vfs.stat(c).size>0;case"-z":return o.length===0;case"-n":return o.length>0;case"-L":return t.vfs.isSymlink(c)}}if(n.length===3){let[s="",o,a=""]=n,c=Number(s),l=Number(a);switch(o){case"=":case"==":return s===a;case"!=":return s!==a;case"<":return s<a;case">":return s>a;case"-eq":return c===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 ah={name:"test",aliases:["["],description:"Evaluate conditional expression",category:"shell",params:["<expression>"],run:({args:n,shell:t,cwd:e})=>{try{return{exitCode:ni([...n],t,e)?0:1}}catch{return{stderr:"test: malformed expression",exitCode:2}}}};var ch={name:"touch",description:"Create or update files",category:"files",params:["<file>"],run:({authUser:n,shell:t,cwd:e,args:r})=>{if(r.length===0)return{stderr:"touch: missing file operand",exitCode:1};for(let i of r){let s=he(e,i);Fe(n,s,"touch"),t.vfs.exists(s)||t.writeFileAsUser(n,s,"")}return{exitCode:0}}};function yy(n){return n.replace(/\\n/g,`
1030
+ `).replace(/\\t/g," ").replace(/\\r/g,"\r").replace(/\\\\/g,"\\")}function lh(n){let t=[],e=yy(n),r=0;for(;r<e.length;){if(r+2<e.length&&e[r+1]==="-"){let i=e.charCodeAt(r),s=e.charCodeAt(r+2);if(i<=s){for(let o=i;o<=s;o++)t.push(String.fromCharCode(o));r+=3;continue}}t.push(e[r]),r++}return t}var uh={name:"tr",description:"Translate or delete characters",category:"text",params:["[-d] [-s] <set1> [set2]"],run:({args:n,stdin:t})=>{let e=ae(n,["-d"]),r=ae(n,["-s"]),i=n.filter(c=>!c.startsWith("-")),s=lh(i[0]??""),o=lh(i[1]??""),a=t??"";if(e){let c=new Set(s);a=[...a].filter(l=>!c.has(l)).join("")}else if(o.length>0){let c=new Map;for(let l=0;l<s.length;l++)c.set(s[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,u)=>c.has(u)?u:l)}return{stdout:a,exitCode:0}}};var fh={name:"tree",description:"Display directory tree",category:"navigation",params:["[path]"],run:({authUser:n,shell:t,cwd:e,args:r})=>{let i=he(e,rr(r,0)??e);return Fe(n,i,"tree"),{stdout:t.vfs.tree(i),exitCode:0}}};var dh={name:"true",description:"Return success exit code",category:"shell",params:[],run:()=>({exitCode:0})},hh={name:"false",description:"Return failure exit code",category:"shell",params:[],run:()=>({exitCode:1})};var ph={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(":"),i=[],s=0;for(let o of n){if(wn(o)){i.push(`${o} is a shell builtin`);continue}let a=!1;for(let c of r){let l=`${c}/${o}`;if(t.vfs.exists(l)){i.push(`${o} is ${l}`),a=!0;break}}a||(i.push(`${o}: not found`),s=1)}return{stdout:i.join(`
1031
+ `),exitCode:s}}};var mh={name:"uname",description:"Print system information",category:"system",params:["[-a] [-s] [-r] [-m]"],run:({shell:n,args:t})=>{let e=ae(t,["-a"]),r="Linux",i=n.properties?.kernel??"5.15.0",s=n.properties?.arch??"x86_64",o=n.hostname;return e?{stdout:`${r} ${o} ${i} #1 SMP ${s} GNU/Linux`,exitCode:0}:ae(t,["-r"])?{stdout:i,exitCode:0}:ae(t,["-m"])?{stdout:s,exitCode:0}:{stdout:r,exitCode:0}}};var gh={name:"uniq",description:"Report or filter out repeated lines",category:"text",params:["[-c] [-d] [-u] [file]"],run:({args:n,stdin:t})=>{let e=ae(n,["-c"]),r=ae(n,["-d"]),i=ae(n,["-u"]),s=(t??"").split(`
1032
+ `),o=[],a=0;for(;a<s.length;){let c=a;for(;c<s.length&&s[c]===s[a];)c++;let l=c-a,u=s[a];if(r&&l===1){a=c;continue}if(i&&l>1){a=c;continue}o.push(e?`${String(l).padStart(4)} ${u}`:u),a=c}return{stdout:o.join(`
1033
+ `),exitCode:0}}};var Ah={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 yh={name:"uptime",description:"Tell how long the system has been running",category:"system",params:["[-p] [-s]"],run:({args:n,shell:t})=>{let e=ae(n,["-p"]),r=ae(n,["-s"]),i=Math.floor((Date.now()-t.startTime)/1e3),s=Math.floor(i/86400),o=Math.floor(i%86400/3600),a=Math.floor(i%3600/60);if(r)return{stdout:new Date(t.startTime).toISOString().slice(0,19).replace("T"," "),exitCode:0};if(e){let h=[];return s>0&&h.push(`${s} day${s>1?"s":""}`),o>0&&h.push(`${o} hour${o>1?"s":""}`),h.push(`${a} minute${a!==1?"s":""}`),{stdout:`up ${h.join(", ")}`,exitCode:0}}let c=new Date().toTimeString().slice(0,8),l=s>0?`${s} day${s>1?"s":""}, ${String(o).padStart(2)}:${String(a).padStart(2,"0")}`:`${String(o).padStart(2)}:${String(a).padStart(2,"0")}`,u=t.users.listActiveSessions().length,f=(Math.random()*.5).toFixed(2);return{stdout:` ${c} up ${l}, ${u} user${u!==1?"s":""}, load average: ${f}, ${f}, ${f}`,exitCode:0}}};var Eh={name:"wc",description:"Count words/lines/bytes",category:"text",params:["[-l] [-w] [-c] [file...]"],run:({authUser:n,shell:t,cwd:e,args:r,stdin:i})=>{let s=ae(r,["-l"]),o=ae(r,["-w"]),a=ae(r,["-c"]),c=!s&&!o&&!a,l=r.filter(h=>!h.startsWith("-")),u=(h,p)=>{let y=h.length===0?0:h.trim().split(`
1034
+ `).length,E=h.trim().split(/\s+/).filter(Boolean).length,S=Buffer.byteLength(h,"utf8"),x=[];return(c||s)&&x.push(String(y).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:u(i??"",""),exitCode:0};let f=[];for(let h of l){let p=he(e,h);try{Fe(n,p,"wc");let y=t.vfs.readFile(p);f.push(u(y,h))}catch{return{stderr:`wc: ${h}: No such file or directory`,exitCode:1}}}return{stdout:f.join(`
1035
+ `),exitCode:0}}};var _h={name:"wget",description:"File downloader (pure fetch)",category:"network",params:["[options] <url>"],run:async({authUser:n,cwd:t,args:e,shell:r})=>{let{flagsWithValues:i,positionals:s}=en(e,{flagsWithValue:["-O","--output-document","-o","--output-file","-P","--directory-prefix","--tries","--timeout"]});if(ae(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(`
1036
+ `),exitCode:0};if(ae(e,["-V","--version"]))return{stdout:"GNU Wget 1.21.3 (virtual) built on Fortune GNU/Linux.",exitCode:0};let o=s[0];if(!o)return{stderr:`wget: missing URL
1037
1037
  Usage: wget [OPTION]... [URL]...`,exitCode:1};let a=o.startsWith("http://")||o.startsWith("https://")?o:`http://${o}`;if(!a)return{stderr:`wget: missing URL
1038
- 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,u=ae(e,["-q","--quiet"]),f=c==="-"?null:c??Af(a),h=f?he(t,l?`${l}/${f}`:f):null;h&&Fe(n,h,"wget");let p=[];u||(p.push(`--${new Date().toISOString()}-- ${a}`),p.push(`Resolving ${new URL(a).host}...`),p.push(`Connecting to ${new URL(a).host}...`));let y;try{y=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(`
1038
+ Usage: wget [OPTION]... [URL]...`,exitCode:1};let c=i.get("-O")??i.get("--output-document")??null,l=i.get("-P")??i.get("--directory-prefix")??null,u=ae(e,["-q","--quiet"]),f=c==="-"?null:c??Ef(a),h=f?he(t,l?`${l}/${f}`:f):null;h&&Fe(n,h,"wget");let p=[];u||(p.push(`--${new Date().toISOString()}-- ${a}`),p.push(`Resolving ${new URL(a).host}...`),p.push(`Connecting to ${new URL(a).host}...`));let y;try{y=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(`
1039
1039
  `),exitCode:4}}if(!y.ok)return p.push(`ERROR ${y.status}: ${y.statusText}`),{stderr:p.join(`
1040
1040
  `),exitCode:8};let E;try{E=await y.text()}catch{return{stderr:"wget: failed to read response",exitCode:1}}if(!u){let S=y.headers.get("content-type")??"application/octet-stream";p.push(`HTTP request sent, awaiting response... ${y.status} ${y.statusText}`),p.push(`Length: ${E.length} [${S}]`)}return c==="-"?{stdout:E,stderr:p.join(`
1041
1041
  `)||void 0,exitCode:0}:h?(r.writeFileAsUser(n,h,E),u||p.push(`Saving to: '${h}'
1042
1042
  ${h} 100%[==================>] ${E.length} B`),{stderr:p.join(`
1043
- `)||void 0,exitCode:0}):{stdout:E,exitCode:0}}};var Eh={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(`
1044
- `),exitCode:i?1:0}}};function to(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 _h={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:to(r);return`${e.username} ${e.tty} ${s} (${e.remoteAddress||"unknown"})`}).join(`
1045
- `),exitCode:0})};var bh={name:"whoami",description:"Print current user",category:"system",params:[],run:({authUser:n})=>({stdout:n,exitCode:0})};var Sh={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),u=(i??"").trim().split(/\s+/).filter(Boolean);if(u.length===0)return{exitCode:0};let f=[c,...l,...u].join(" ");return wt(f,n,t,e,r,o,void 0,a)}};var gy=[Ud,kf,hd,lh,xf,oh,Wd,Ad,Bf,yd,cd,ld,vf,ud,fd,Kf,zf,qd,bf,Jd,ph,Ah,Xf,nh,Pf,ch,ih,Sh,Df,rh,Yf,jf,Sf,bh,_h,id,od,Gf,hh,Dd,ad,Lf,Ff,Tf,Xd,Md,Hf,Qf,qf,Kd,mh,zd,Nf,Wf,_d,sd,Rf,yh,hf,Od,Mf,th,eh,Nd,Ef,_f,Uf,$f,Eh,dh,gd,mf,gf,sh,Zd,rd,Ld,Qd,Of,Gd,Yd,jd,uh,fh,Pd,Td,Rd,Hd,gh,Vf,pd],xh=[],Wi=new Map,no=null,Ay=nd(()=>Ec().map(n=>n.name));function yc(){Wi.clear();for(let n of Ec()){Wi.set(n.name,n);for(let t of n.aliases??[])Wi.set(t,n)}no=Array.from(Wi.keys()).sort()}function Ec(){return[...gy,...xh,Ay]}function oc(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");xh.push(t),yc()}function ac(n,t,e){return{name:n,params:t,run:e}}function cc(){return no||yc(),no}function lc(){return Ec()}function wn(n){return no||yc(),Wi.get(n.toLowerCase())}var Tn=Yt(require("node:os"),1);var Bh=require("node:events"),rt=Yt(require("node:fs"),1),tn=Yt(require("node:path"),1),Er=require("node:zlib");var xc=Buffer.from([86,70,83,33]),yy=1,_c=1,wh=2,bc=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(_c),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt),n.writeFloat64(e.updatedAt),n.writeUint8(e.compressed?1:0),n.writeBytes(e.content)}else if(t.type==="stub"){let e=t;n.writeUint8(_c),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt),n.writeFloat64(e.updatedAt),n.writeUint8(0),n.writeBytes(Buffer.from(e.stubContent,"utf8"))}else{let e=t;n.writeUint8(wh),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt),n.writeFloat64(e.updatedAt);let r=Object.values(e.children);n.writeUint32(r.length);for(let s of r)Ih(n,s)}}function wc(n){let t=new bc;return t.write(xc),t.writeUint8(yy),Ih(t,n),t.toBuffer()}var Sc=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 Ch(n){let t=n.readUint8(),e=n.readString(),r=n.readUint32(),s=n.readFloat64(),i=n.readFloat64();if(t===_c){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=Object.create(null);for(let c=0;c<o;c++){let l=Ch(n);a[l.name]=l}return{type:"directory",name:e,mode:r,createdAt:s,updatedAt:i,children:a,_childCount:o}}throw new Error(`[VFS binary] Unknown node type: 0x${t.toString(16)}`)}function or(n){if(n.length<5)throw new Error("[VFS binary] Buffer too short");if(!n.slice(0,4).equals(xc))throw new Error("[VFS binary] Invalid magic \u2014 not a VFS binary snapshot");let e=new Sc(n);for(let s=0;s<5;s++)e.readUint8();let r=Ch(e);if(r.type!=="directory")throw new Error("[VFS binary] Root node must be a directory");return r}function kh(n){return n.length>=4&&n.slice(0,4).equals(xc)}var It=Yt(require("node:fs"),1),ut={WRITE:1,MKDIR:2,REMOVE:3,CHMOD:4,MOVE:5,SYMLINK:6},qi="utf8";function Ey(n,t,e){let r=Buffer.from(e,qi);return n.writeUInt16LE(r.length,t),r.copy(n,t+2),2+r.length}function _y(n){let t=Buffer.from(n.path,qi),e=0;n.op===ut.WRITE?e=4+(n.content?.length??0)+4:n.op===ut.MKDIR?e=4:n.op===ut.REMOVE?e=0:n.op===ut.CHMOD?e=4:(n.op===ut.MOVE||n.op===ut.SYMLINK)&&(e=2+Buffer.byteLength(n.dest??"",qi));let r=3+t.length+e,s=Buffer.allocUnsafe(r),i=0;if(s.writeUInt8(n.op,i++),s.writeUInt16LE(t.length,i),i+=2,t.copy(s,i),i+=t.length,n.op===ut.WRITE){let o=n.content??Buffer.alloc(0);s.writeUInt32LE(o.length,i),i+=4,o.copy(s,i),i+=o.length,s.writeUInt32LE(n.mode??420,i),i+=4}else n.op===ut.MKDIR?(s.writeUInt32LE(n.mode??493,i),i+=4):n.op===ut.CHMOD?(s.writeUInt32LE(n.mode??420,i),i+=4):(n.op===ut.MOVE||n.op===ut.SYMLINK)&&(i+=Ey(s,i,n.dest??""));return s}function by(n){let t=[],e=0;try{for(;e<n.length&&!(e+3>n.length);){let r=n.readUInt8(e++),s=n.readUInt16LE(e);if(e+=2,e+s>n.length)break;let i=n.subarray(e,e+s).toString(qi);if(e+=s,r===ut.WRITE){if(e+4>n.length)break;let o=n.readUInt32LE(e);if(e+=4,e+o+4>n.length)break;let a=Buffer.from(n.subarray(e,e+o));e+=o;let c=n.readUInt32LE(e);e+=4,t.push({op:r,path:i,content:a,mode:c})}else if(r===ut.MKDIR){if(e+4>n.length)break;let o=n.readUInt32LE(e);e+=4,t.push({op:r,path:i,mode:o})}else if(r===ut.REMOVE)t.push({op:r,path:i});else if(r===ut.CHMOD){if(e+4>n.length)break;let o=n.readUInt32LE(e);e+=4,t.push({op:r,path:i,mode:o})}else if(r===ut.MOVE||r===ut.SYMLINK){if(e+2>n.length)break;let o=n.readUInt16LE(e);if(e+=2,e+o>n.length)break;let a=n.subarray(e,e+o).toString(qi);e+=o,t.push({op:r,path:i,dest:a})}else break}}catch{}return t}function vh(n,t){let e=_y(t);if(It.existsSync(n)){let r=It.openSync(n,It.constants.O_WRONLY|It.constants.O_CREAT|It.constants.O_APPEND);try{It.writeSync(r,e)}finally{It.closeSync(r)}}else It.existsSync(".vfs")||It.mkdirSync(".vfs"),It.writeFileSync(n,e)}function Ic(n){if(!It.existsSync(n))return[];let t=It.readFileSync(n);return t.length===0?[]:by(t)}function Nh(n){It.existsSync(n)&&It.unlinkSync(n)}var ro=Yt(require("node:path"),1);function ft(n){if(!n||n.trim()==="")return"/";let t=ro.posix.normalize(n.startsWith("/")?n:`/${n}`);return t===""?"/":t}function Sy(n){return n.split("/").filter(Boolean)}function Kt(n,t){let e=ft(t);if(e==="/")return n;let r=Sy(e),s=n;for(let i of r){if(s.type!=="directory")throw new Error(`Path '${e}' does not exist.`);let o=s.children[i];if(!o)throw new Error(`Path '${e}' does not exist.`);s=o}return s}function yr(n,t,e,r){let s=ft(t);if(s==="/")throw new Error("Root path has no parent directory.");let i=ro.posix.dirname(s),o=ro.posix.basename(s);if(!o)throw new Error(`Invalid path '${t}'.`);e&&r(i);let a=Kt(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 Bh.EventEmitter{root;mode;snapshotFile;journalFile;evictionThreshold;flushAfterNWrites;_writesSinceFlush=0;_flushTimer=null;_dirty=!1;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=tn.resolve(t.snapshotPath,"vfs-snapshot.vfsb"),this.journalFile=tn.resolve(t.snapshotPath,"vfs-journal.bin"),this.evictionThreshold=t.evictionThresholdBytes??64*1024,this.flushAfterNWrites=t.flushAfterNWrites??500;let e=t.flushIntervalMs??1e3;e>0&&(this._flushTimer=setInterval(()=>{this._dirty&&this._autoFlush()},e),typeof this._flushTimer=="object"&&this._flushTimer!==null&&"unref"in this._flushTimer&&this._flushTimer.unref())}else this.snapshotFile=null,this.journalFile=null,this.evictionThreshold=0,this.flushAfterNWrites=0;this.root=this.makeDir("",493)}makeDir(t,e){let r=Date.now();return{type:"directory",name:t,mode:e,createdAt:r,updatedAt:r,children:Object.create(null),_childCount:0}}makeFile(t,e,r,s){let i=Date.now();return{type:"file",name:t,content:e,mode:r,compressed:s,createdAt:i,updatedAt:i}}makeStub(t,e,r){let s=Date.now();return{type:"stub",name:t,stubContent:e,mode:r,createdAt:s,updatedAt:s}}writeStub(t,e,r=420){let s=ft(t),{parent:i,name:o}=yr(this.root,s,!0,c=>this.mkdirRecursive(c,493)),a=i.children[o];if(a?.type==="directory")throw new Error(`Cannot write stub '${s}': path is a directory.`);a?.type!=="file"&&(a||i._childCount++,i.children[o]=this.makeStub(o,e,r))}mkdirRecursive(t,e){let r=ft(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[a];if(!c)c=this.makeDir(a,e),i.children[a]=c,i._childCount++,this.emit("dir:create",{path:o,mode:e}),this._journal({op:ut.MKDIR,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)){if(!rt.existsSync(this.snapshotFile)){if(this.journalFile){let t=Ic(this.journalFile);t.length>0&&this._replayJournal(t)}return}try{let t=rt.readFileSync(this.snapshotFile);if(kh(t))this.root=or(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.")}if(this.emit("snapshot:restore",{path:this.snapshotFile}),this.journalFile){let e=Ic(this.journalFile);e.length>0&&this._replayJournal(e)}}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=tn.dirname(this.snapshotFile);rt.mkdirSync(t,{recursive:!0});let e=this.root,r=wc(e);rt.writeFileSync(this.snapshotFile,r),this.journalFile&&Nh(this.journalFile),this._dirty=!1,this._writesSinceFlush=0,this.emit("mirror:flush",{path:this.snapshotFile}),this.evictLargeFiles()}getMode(){return this.mode}getSnapshotPath(){return this.snapshotFile}async _autoFlush(){this._dirty&&await this.flushMirror()}_markDirty(){this._dirty=!0,this.flushAfterNWrites>0&&(this._writesSinceFlush++,this._writesSinceFlush>=this.flushAfterNWrites&&(this._writesSinceFlush=0,this._autoFlush()))}async stopAutoFlush(){this._flushTimer!==null&&(clearInterval(this._flushTimer),this._flushTimer=null),this._dirty&&await this.flushMirror()}importRootTree(t){let e=this._replayMode;this._replayMode=!0;try{this.root=t}finally{this._replayMode=e}}mergeRootTree(t){let e=this._replayMode;this._replayMode=!0;try{this._mergeDir(this.root,t)}finally{this._replayMode=e}}_mergeDir(t,e){for(let[r,s]of Object.entries(e.children)){let i=t.children[r];s.type==="directory"?i?i.type==="directory"&&this._mergeDir(i,s):(t.children[r]=s,t._childCount++):i||(t.children[r]=s,t._childCount++)}}encodeBinary(){return wc(this.root)}releaseTree(){this.root=this.makeDir("",493)}_replayMode=!1;_journal(t){this.journalFile&&!this._replayMode&&(vh(this.journalFile,t),this._markDirty())}_replayJournal(t){this._replayMode=!0;try{for(let e of t)try{e.op===ut.WRITE?this.writeFile(e.path,e.content??Buffer.alloc(0),{mode:e.mode}):e.op===ut.MKDIR?this.mkdir(e.path,e.mode):e.op===ut.REMOVE?this.exists(e.path)&&this.remove(e.path,{recursive:!0}):e.op===ut.CHMOD?this.exists(e.path)&&this.chmod(e.path,e.mode??420):e.op===ut.MOVE?this.exists(e.path)&&e.dest&&this.move(e.path,e.dest):e.op===ut.SYMLINK&&e.dest&&this.symlink(e.dest,e.path)}catch{}}finally{this._replayMode=!1}}evictLargeFiles(){!this.snapshotFile||this.evictionThreshold===0||rt.existsSync(this.snapshotFile)&&this._evictDir(this.root)}_evictDir(t){for(let e of Object.values(t.children))if(e.type==="directory")this._evictDir(e);else if(e.type==="file"&&!e.evicted){let r=e.compressed?e.size??e.content.length*2:e.content.length;r>this.evictionThreshold&&(e.size=r,e.content=Buffer.alloc(0),e.evicted=!0)}}_reloadEvicted(t,e){if(!(!t.evicted||!this.snapshotFile)&&rt.existsSync(this.snapshotFile))try{let r=rt.readFileSync(this.snapshotFile),s=or(r),i=e.split("/").filter(Boolean),o=s;for(let a of i){if(o.type!=="directory")return;let c=o.children[a];if(!c)return;o=c}o.type==="file"&&(t.content=o.content,t.compressed=o.compressed,t.evicted=void 0)}catch{}}mount(t,e,{readOnly:r=!0}={}){if(n.isBrowser)return;let s=ft(t),i=tn.resolve(e);if(!rt.existsSync(i))throw new Error(`VirtualFileSystem.mount: host path does not exist: "${i}"`);if(!rt.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=ft(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=ft(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?tn.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=ft(t),s=(()=>{try{return Kt(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=tn.dirname(s.fullHostPath);rt.existsSync(p)||rt.mkdirSync(p,{recursive:!0}),rt.writeFileSync(s.fullHostPath,Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"));return}let i=ft(t),{parent:o,name:a}=yr(this.root,i,!0,p=>this.mkdirRecursive(p,493)),c=o.children[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"),u=r.compress??!1,f=u?(0,Er.gzipSync)(l):l,h=r.mode??420;if(c&&c.type==="file"){let p=c;p.content=f,p.compressed=u,p.mode=h,p.updatedAt=Date.now()}else c||o._childCount++,o.children[a]=this.makeFile(a,f,h,u);this.emit("file:write",{path:i,size:f.length}),this._journal({op:ut.WRITE,path:i,content:l,mode:h})}readFile(t){let e=this.resolveMount(t);if(e){if(!rt.existsSync(e.fullHostPath))throw new Error(`ENOENT: no such file or directory, open '${e.fullHostPath}'`);return rt.readFileSync(e.fullHostPath,"utf8")}let r=ft(t),s=Kt(this.root,r);if(s.type==="stub")return this.emit("file:read",{path:r,size:s.stubContent.length}),s.stubContent;if(s.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let i=s;i.evicted&&this._reloadEvicted(i,r);let o=i.compressed?(0,Er.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(!rt.existsSync(e.fullHostPath))throw new Error(`ENOENT: no such file or directory, open '${e.fullHostPath}'`);return rt.readFileSync(e.fullHostPath)}let r=ft(t),s=Kt(this.root,r);if(s.type==="stub"){let a=Buffer.from(s.stubContent,"utf8");return this.emit("file:read",{path:r,size:a.length}),a}if(s.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let i=s;i.evicted&&this._reloadEvicted(i,r);let o=i.compressed?(0,Er.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 rt.existsSync(e.fullHostPath);try{return Kt(this.root,ft(t)),!0}catch{return!1}}chmod(t,e){let r=ft(t);Kt(this.root,r).mode=e,this._journal({op:ut.CHMOD,path:r,mode:e})}stat(t){let e=this.resolveMount(t);if(e){if(!rt.existsSync(e.fullHostPath))throw new Error(`ENOENT: stat '${e.fullHostPath}'`);let a=rt.statSync(e.fullHostPath),c=e.relPath.split("/").pop()??e.fullHostPath.split("/").pop()??"",l=a.mtime;return a.isDirectory()?{type:"directory",name:c,path:ft(t),mode:493,createdAt:a.birthtime,updatedAt:l,childrenCount:rt.readdirSync(e.fullHostPath).length}:{type:"file",name:c,path:ft(t),mode:e.readOnly?292:420,createdAt:a.birthtime,updatedAt:l,compressed:!1,size:a.size}}let r=ft(t),s=Kt(this.root,r),i=r==="/"?"":tn.posix.basename(r);if(s.type==="stub"){let a=s;return{type:"file",name:i,path:r,mode:a.mode,createdAt:new Date(a.createdAt),updatedAt:new Date(a.updatedAt),compressed:!1,size:a.stubContent.length}}if(s.type==="file"){let a=s;return{type:"file",name:i,path:r,mode:a.mode,createdAt:new Date(a.createdAt),updatedAt:new Date(a.updatedAt),compressed:a.compressed,size:a.evicted?a.size??0:a.content.length}}let o=s;return{type:"directory",name:i,path:r,mode:o.mode,createdAt:new Date(o.createdAt),updatedAt:new Date(o.updatedAt),childrenCount:o._childCount}}list(t="/"){let e=this.resolveMount(t);if(e){if(!rt.existsSync(e.fullHostPath))return[];try{return rt.readdirSync(e.fullHostPath).sort()}catch{return[]}}let r=ft(t),s=Kt(this.root,r);if(s.type!=="directory")throw new Error(`Cannot list '${t}': not a directory.`);return Object.keys(s.children).sort()}tree(t="/"){let e=ft(t),r=Kt(this.root,e);if(r.type!=="directory")throw new Error(`Cannot render tree for '${t}': not a directory.`);let s=t==="/"?"/":tn.posix.basename(e);return this.renderTreeLines(r,s)}renderTreeLines(t,e){let r=[e],s=Object.keys(t.children).sort();for(let i=0;i<s.length;i++){let o=s[i],a=t.children[o],c=i===s.length-1,l=c?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",u=c?" ":"\u2502 ";if(r.push(`${l}${o}`),a.type==="directory"){let f=this.renderTreeLines(a,"").split(`
1043
+ `)||void 0,exitCode:0}):{stdout:E,exitCode:0}}};var bh={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(":"),i=[],s=!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"){i.push(l),a=!0;break}}a||(s=!0)}return i.length===0?{exitCode:1}:{stdout:i.join(`
1044
+ `),exitCode:s?1:0}}};function ro(n){let t=n.toLocaleString("en-US",{weekday:"short"}),e=n.toLocaleString("en-US",{month:"short"}),r=n.getDate().toString().padStart(2,"0"),i=n.getHours().toString().padStart(2,"0"),s=n.getMinutes().toString().padStart(2,"0"),o=n.getSeconds().toString().padStart(2,"0"),a=n.getFullYear();return`${t} ${e} ${r} ${i}:${s}:${o} ${a}`}var Sh={name:"who",description:"Show active sessions",category:"system",params:[],run:({shell:n})=>({stdout:n.users.listActiveSessions().map(e=>{let r=new Date(e.startedAt),i=Number.isNaN(r.getTime())?e.startedAt:ro(r);return`${e.username} ${e.tty} ${i} (${e.remoteAddress||"unknown"})`}).join(`
1045
+ `),exitCode:0})};var xh={name:"whoami",description:"Print current user",category:"system",params:[],run:({authUser:n})=>({stdout:n,exitCode:0})};var wh={name:"xargs",description:"Build and execute command lines from stdin",category:"text",params:["[command] [args...]"],run:async({authUser:n,hostname:t,mode:e,cwd:r,args:i,stdin:s,shell:o,env:a})=>{let c=i[0]??"echo",l=i.slice(1),u=(s??"").trim().split(/\s+/).filter(Boolean);if(u.length===0)return{exitCode:0};let f=[c,...l,...u].join(" ");return wt(f,n,t,e,r,o,void 0,a)}};var Ey=[Fd,Nf,md,fh,If,ch,Kd,Ed,Pf,_d,ud,fd,Bf,dd,hd,zf,Yf,Vd,xf,eh,gh,Eh,Zf,ih,Of,uh,oh,wh,$f,sh,Xf,Jf,wf,xh,Sh,od,cd,jf,mh,$d,ld,Uf,Qf,Mf,Zd,Dd,Wf,qf,Vf,zd,Ah,Yd,Rf,Kf,Sd,ad,Tf,_h,mf,Ld,Df,rh,nh,Rd,bf,Sf,Ff,Hf,bh,ph,yd,Af,yf,ah,th,sd,Ud,qd,Lf,jd,Xd,Jd,dh,hh,Od,Md,Td,Wd,yh,Gf,gd],Ih=[],qi=new Map,io=null,_y=id(()=>bc().map(n=>n.name));function _c(){qi.clear();for(let n of bc()){qi.set(n.name,n);for(let t of n.aliases??[])qi.set(t,n)}io=Array.from(qi.keys()).sort()}function bc(){return[...Ey,...Ih,_y]}function cc(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");Ih.push(t),_c()}function lc(n,t,e){return{name:n,params:t,run:e}}function uc(){return io||_c(),io}function fc(){return bc()}function wn(n){return io||_c(),qi.get(n.toLowerCase())}var Tn=Yt(require("node:os"),1);var Ph=require("node:events"),rt=Yt(require("node:fs"),1),tn=Yt(require("node:path"),1),_r=require("node:zlib");var Ic=Buffer.from([86,70,83,33]),by=1,Sc=1,Ch=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 kh(n,t){if(t.type==="file"){let e=t;n.writeUint8(Sc),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt),n.writeFloat64(e.updatedAt),n.writeUint8(e.compressed?1:0),n.writeBytes(e.content)}else if(t.type==="stub"){let e=t;n.writeUint8(Sc),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt),n.writeFloat64(e.updatedAt),n.writeUint8(0),n.writeBytes(Buffer.from(e.stubContent,"utf8"))}else{let e=t;n.writeUint8(Ch),n.writeString(e.name),n.writeUint32(e.mode),n.writeFloat64(e.createdAt),n.writeFloat64(e.updatedAt);let r=Object.values(e.children);n.writeUint32(r.length);for(let i of r)kh(n,i)}}function Cc(n){let t=new xc;return t.write(Ic),t.writeUint8(by),kh(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 vh(n){let t=n.readUint8(),e=n.readString(),r=n.readUint32(),i=n.readFloat64(),s=n.readFloat64();if(t===Sc){let o=n.readUint8()===1,a=n.readBytes();return{type:"file",name:e,mode:r,createdAt:i,updatedAt:s,compressed:o,content:a}}if(t===Ch){let o=n.readUint32(),a=Object.create(null);for(let c=0;c<o;c++){let l=vh(n);a[l.name]=l}return{type:"directory",name:e,mode:r,createdAt:i,updatedAt:s,children:a,_childCount:o}}throw new Error(`[VFS binary] Unknown node type: 0x${t.toString(16)}`)}function ar(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 i=0;i<5;i++)e.readUint8();let r=vh(e);if(r.type!=="directory")throw new Error("[VFS binary] Root node must be a directory");return r}function Nh(n){return n.length>=4&&n.slice(0,4).equals(Ic)}var It=Yt(require("node:fs"),1),ut={WRITE:1,MKDIR:2,REMOVE:3,CHMOD:4,MOVE:5,SYMLINK:6},Ki="utf8";function Sy(n,t,e){let r=Buffer.from(e,Ki);return n.writeUInt16LE(r.length,t),r.copy(n,t+2),2+r.length}function xy(n){let t=Buffer.from(n.path,Ki),e=0;n.op===ut.WRITE?e=4+(n.content?.length??0)+4:n.op===ut.MKDIR?e=4:n.op===ut.REMOVE?e=0:n.op===ut.CHMOD?e=4:(n.op===ut.MOVE||n.op===ut.SYMLINK)&&(e=2+Buffer.byteLength(n.dest??"",Ki));let r=3+t.length+e,i=Buffer.allocUnsafe(r),s=0;if(i.writeUInt8(n.op,s++),i.writeUInt16LE(t.length,s),s+=2,t.copy(i,s),s+=t.length,n.op===ut.WRITE){let o=n.content??Buffer.alloc(0);i.writeUInt32LE(o.length,s),s+=4,o.copy(i,s),s+=o.length,i.writeUInt32LE(n.mode??420,s),s+=4}else n.op===ut.MKDIR?(i.writeUInt32LE(n.mode??493,s),s+=4):n.op===ut.CHMOD?(i.writeUInt32LE(n.mode??420,s),s+=4):(n.op===ut.MOVE||n.op===ut.SYMLINK)&&(s+=Sy(i,s,n.dest??""));return i}function wy(n){let t=[],e=0;try{for(;e<n.length&&!(e+3>n.length);){let r=n.readUInt8(e++),i=n.readUInt16LE(e);if(e+=2,e+i>n.length)break;let s=n.subarray(e,e+i).toString(Ki);if(e+=i,r===ut.WRITE){if(e+4>n.length)break;let o=n.readUInt32LE(e);if(e+=4,e+o+4>n.length)break;let a=Buffer.from(n.subarray(e,e+o));e+=o;let c=n.readUInt32LE(e);e+=4,t.push({op:r,path:s,content:a,mode:c})}else if(r===ut.MKDIR){if(e+4>n.length)break;let o=n.readUInt32LE(e);e+=4,t.push({op:r,path:s,mode:o})}else if(r===ut.REMOVE)t.push({op:r,path:s});else if(r===ut.CHMOD){if(e+4>n.length)break;let o=n.readUInt32LE(e);e+=4,t.push({op:r,path:s,mode:o})}else if(r===ut.MOVE||r===ut.SYMLINK){if(e+2>n.length)break;let o=n.readUInt16LE(e);if(e+=2,e+o>n.length)break;let a=n.subarray(e,e+o).toString(Ki);e+=o,t.push({op:r,path:s,dest:a})}else break}}catch{}return t}function Bh(n,t){let e=xy(t);if(It.existsSync(n)){let r=It.openSync(n,It.constants.O_WRONLY|It.constants.O_CREAT|It.constants.O_APPEND);try{It.writeSync(r,e)}finally{It.closeSync(r)}}else It.existsSync(".vfs")||It.mkdirSync(".vfs"),It.writeFileSync(n,e)}function kc(n){if(!It.existsSync(n))return[];let t=It.readFileSync(n);return t.length===0?[]:wy(t)}function Rh(n){It.existsSync(n)&&It.unlinkSync(n)}var so=Yt(require("node:path"),1);function ft(n){if(!n||n.trim()==="")return"/";let t=so.posix.normalize(n.startsWith("/")?n:`/${n}`);return t===""?"/":t}function Iy(n){return n.split("/").filter(Boolean)}function Kt(n,t){let e=ft(t);if(e==="/")return n;let r=Iy(e),i=n;for(let s of r){if(i.type!=="directory")throw new Error(`Path '${e}' does not exist.`);let o=i.children[s];if(!o)throw new Error(`Path '${e}' does not exist.`);i=o}return i}function Er(n,t,e,r){let i=ft(t);if(i==="/")throw new Error("Root path has no parent directory.");let s=so.posix.dirname(i),o=so.posix.basename(i);if(!o)throw new Error(`Invalid path '${t}'.`);e&&r(s);let a=Kt(n,s);if(a.type!=="directory")throw new Error(`Parent path '${s}' is not a directory.`);return{parent:a,name:o}}var vc=class n extends Ph.EventEmitter{root;mode;snapshotFile;journalFile;evictionThreshold;flushAfterNWrites;_writesSinceFlush=0;_flushTimer=null;_dirty=!1;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=tn.resolve(t.snapshotPath,"vfs-snapshot.vfsb"),this.journalFile=tn.resolve(t.snapshotPath,"vfs-journal.bin"),this.evictionThreshold=t.evictionThresholdBytes??64*1024,this.flushAfterNWrites=t.flushAfterNWrites??500;let e=t.flushIntervalMs??1e3;e>0&&(this._flushTimer=setInterval(()=>{this._dirty&&this._autoFlush()},e),typeof this._flushTimer=="object"&&this._flushTimer!==null&&"unref"in this._flushTimer&&this._flushTimer.unref())}else this.snapshotFile=null,this.journalFile=null,this.evictionThreshold=0,this.flushAfterNWrites=0;this.root=this.makeDir("",493)}makeDir(t,e){let r=Date.now();return{type:"directory",name:t,mode:e,createdAt:r,updatedAt:r,children:Object.create(null),_childCount:0}}makeFile(t,e,r,i){let s=Date.now();return{type:"file",name:t,content:e,mode:r,compressed:i,createdAt:s,updatedAt:s}}makeStub(t,e,r){let i=Date.now();return{type:"stub",name:t,stubContent:e,mode:r,createdAt:i,updatedAt:i}}writeStub(t,e,r=420){let i=ft(t),{parent:s,name:o}=Er(this.root,i,!0,c=>this.mkdirRecursive(c,493)),a=s.children[o];if(a?.type==="directory")throw new Error(`Cannot write stub '${i}': path is a directory.`);a?.type!=="file"&&(a||s._childCount++,s.children[o]=this.makeStub(o,e,r))}mkdirRecursive(t,e){let r=ft(t);if(r==="/")return;let i=r.split("/").filter(Boolean),s=this.root,o="";for(let a of i){o+=`/${a}`;let c=s.children[a];if(!c)c=this.makeDir(a,e),s.children[a]=c,s._childCount++,this.emit("dir:create",{path:o,mode:e}),this._journal({op:ut.MKDIR,path:o,mode:e});else if(c.type!=="directory")throw new Error(`Cannot create directory '${o}': path is a file.`);s=c}}async restoreMirror(){if(!(this.mode!=="fs"||!this.snapshotFile)){if(!rt.existsSync(this.snapshotFile)){if(this.journalFile){let t=kc(this.journalFile);t.length>0&&this._replayJournal(t)}return}try{let t=rt.readFileSync(this.snapshotFile);if(Nh(t))this.root=ar(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.")}if(this.emit("snapshot:restore",{path:this.snapshotFile}),this.journalFile){let e=kc(this.journalFile);e.length>0&&this._replayJournal(e)}}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=tn.dirname(this.snapshotFile);rt.mkdirSync(t,{recursive:!0});let e=this.root,r=Cc(e);rt.writeFileSync(this.snapshotFile,r),this.journalFile&&Rh(this.journalFile),this._dirty=!1,this._writesSinceFlush=0,this.emit("mirror:flush",{path:this.snapshotFile}),this.evictLargeFiles()}getMode(){return this.mode}getSnapshotPath(){return this.snapshotFile}async _autoFlush(){this._dirty&&await this.flushMirror()}_markDirty(){this._dirty=!0,this.flushAfterNWrites>0&&(this._writesSinceFlush++,this._writesSinceFlush>=this.flushAfterNWrites&&(this._writesSinceFlush=0,this._autoFlush()))}async stopAutoFlush(){this._flushTimer!==null&&(clearInterval(this._flushTimer),this._flushTimer=null),this._dirty&&await this.flushMirror()}importRootTree(t){let e=this._replayMode;this._replayMode=!0;try{this.root=t}finally{this._replayMode=e}}mergeRootTree(t){let e=this._replayMode;this._replayMode=!0;try{this._mergeDir(this.root,t)}finally{this._replayMode=e}}_mergeDir(t,e){for(let[r,i]of Object.entries(e.children)){let s=t.children[r];i.type==="directory"?s?s.type==="directory"&&this._mergeDir(s,i):(t.children[r]=i,t._childCount++):s||(t.children[r]=i,t._childCount++)}}encodeBinary(){return Cc(this.root)}releaseTree(){this.root=this.makeDir("",493)}_replayMode=!1;_journal(t){this.journalFile&&!this._replayMode&&(Bh(this.journalFile,t),this._markDirty())}_replayJournal(t){this._replayMode=!0;try{for(let e of t)try{e.op===ut.WRITE?this.writeFile(e.path,e.content??Buffer.alloc(0),{mode:e.mode}):e.op===ut.MKDIR?this.mkdir(e.path,e.mode):e.op===ut.REMOVE?this.exists(e.path)&&this.remove(e.path,{recursive:!0}):e.op===ut.CHMOD?this.exists(e.path)&&this.chmod(e.path,e.mode??420):e.op===ut.MOVE?this.exists(e.path)&&e.dest&&this.move(e.path,e.dest):e.op===ut.SYMLINK&&e.dest&&this.symlink(e.dest,e.path)}catch{}}finally{this._replayMode=!1}}evictLargeFiles(){!this.snapshotFile||this.evictionThreshold===0||rt.existsSync(this.snapshotFile)&&this._evictDir(this.root)}_evictDir(t){for(let e of Object.values(t.children))if(e.type==="directory")this._evictDir(e);else if(e.type==="file"&&!e.evicted){let r=e.compressed?e.size??e.content.length*2:e.content.length;r>this.evictionThreshold&&(e.size=r,e.content=Buffer.alloc(0),e.evicted=!0)}}_reloadEvicted(t,e){if(!(!t.evicted||!this.snapshotFile)&&rt.existsSync(this.snapshotFile))try{let r=rt.readFileSync(this.snapshotFile),i=ar(r),s=e.split("/").filter(Boolean),o=i;for(let a of s){if(o.type!=="directory")return;let c=o.children[a];if(!c)return;o=c}o.type==="file"&&(t.content=o.content,t.compressed=o.compressed,t.evicted=void 0)}catch{}}mount(t,e,{readOnly:r=!0}={}){if(n.isBrowser)return;let i=ft(t),s=tn.resolve(e);if(!rt.existsSync(s))throw new Error(`VirtualFileSystem.mount: host path does not exist: "${s}"`);if(!rt.statSync(s).isDirectory())throw new Error(`VirtualFileSystem.mount: host path is not a directory: "${s}"`);this.mkdir(i),this.mounts.set(i,{hostPath:s,readOnly:r}),this.emit("mount",{vPath:i,hostPath:s,readOnly:r})}unmount(t){let e=ft(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=ft(t),r=[...this.mounts.entries()].sort(([i],[s])=>s.length-i.length);for(let[i,s]of r)if(e===i||e.startsWith(`${i}/`)){let o=e.slice(i.length).replace(/^\//,""),a=o?tn.join(s.hostPath,o):s.hostPath;return{hostPath:s.hostPath,readOnly:s.readOnly,relPath:o,fullHostPath:a}}return null}mkdir(t,e=493){let r=ft(t),i=(()=>{try{return Kt(this.root,r)}catch{return null}})();if(i&&i.type!=="directory")throw new Error(`Cannot create directory '${r}': path is a file.`);this.mkdirRecursive(r,e)}writeFile(t,e,r={}){let i=this.resolveMount(t);if(i){if(i.readOnly)throw new Error(`EROFS: read-only file system, open '${i.fullHostPath}'`);let p=tn.dirname(i.fullHostPath);rt.existsSync(p)||rt.mkdirSync(p,{recursive:!0}),rt.writeFileSync(i.fullHostPath,Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"));return}let s=ft(t),{parent:o,name:a}=Er(this.root,s,!0,p=>this.mkdirRecursive(p,493)),c=o.children[a];if(c?.type==="directory")throw new Error(`Cannot write file '${s}': path is a directory.`);let l=Buffer.isBuffer(e)?e:Buffer.from(e,"utf8"),u=r.compress??!1,f=u?(0,_r.gzipSync)(l):l,h=r.mode??420;if(c&&c.type==="file"){let p=c;p.content=f,p.compressed=u,p.mode=h,p.updatedAt=Date.now()}else c||o._childCount++,o.children[a]=this.makeFile(a,f,h,u);this.emit("file:write",{path:s,size:f.length}),this._journal({op:ut.WRITE,path:s,content:l,mode:h})}readFile(t){let e=this.resolveMount(t);if(e){if(!rt.existsSync(e.fullHostPath))throw new Error(`ENOENT: no such file or directory, open '${e.fullHostPath}'`);return rt.readFileSync(e.fullHostPath,"utf8")}let r=ft(t),i=Kt(this.root,r);if(i.type==="stub")return this.emit("file:read",{path:r,size:i.stubContent.length}),i.stubContent;if(i.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let s=i;s.evicted&&this._reloadEvicted(s,r);let o=s.compressed?(0,_r.gunzipSync)(s.content):s.content;return this.emit("file:read",{path:r,size:o.length}),o.toString("utf8")}readFileRaw(t){let e=this.resolveMount(t);if(e){if(!rt.existsSync(e.fullHostPath))throw new Error(`ENOENT: no such file or directory, open '${e.fullHostPath}'`);return rt.readFileSync(e.fullHostPath)}let r=ft(t),i=Kt(this.root,r);if(i.type==="stub"){let a=Buffer.from(i.stubContent,"utf8");return this.emit("file:read",{path:r,size:a.length}),a}if(i.type!=="file")throw new Error(`Cannot read '${t}': not a file.`);let s=i;s.evicted&&this._reloadEvicted(s,r);let o=s.compressed?(0,_r.gunzipSync)(s.content):s.content;return this.emit("file:read",{path:r,size:o.length}),o}exists(t){let e=this.resolveMount(t);if(e)return rt.existsSync(e.fullHostPath);try{return Kt(this.root,ft(t)),!0}catch{return!1}}chmod(t,e){let r=ft(t);Kt(this.root,r).mode=e,this._journal({op:ut.CHMOD,path:r,mode:e})}stat(t){let e=this.resolveMount(t);if(e){if(!rt.existsSync(e.fullHostPath))throw new Error(`ENOENT: stat '${e.fullHostPath}'`);let a=rt.statSync(e.fullHostPath),c=e.relPath.split("/").pop()??e.fullHostPath.split("/").pop()??"",l=a.mtime;return a.isDirectory()?{type:"directory",name:c,path:ft(t),mode:493,createdAt:a.birthtime,updatedAt:l,childrenCount:rt.readdirSync(e.fullHostPath).length}:{type:"file",name:c,path:ft(t),mode:e.readOnly?292:420,createdAt:a.birthtime,updatedAt:l,compressed:!1,size:a.size}}let r=ft(t),i=Kt(this.root,r),s=r==="/"?"":tn.posix.basename(r);if(i.type==="stub"){let a=i;return{type:"file",name:s,path:r,mode:a.mode,createdAt:new Date(a.createdAt),updatedAt:new Date(a.updatedAt),compressed:!1,size:a.stubContent.length}}if(i.type==="file"){let a=i;return{type:"file",name:s,path:r,mode:a.mode,createdAt:new Date(a.createdAt),updatedAt:new Date(a.updatedAt),compressed:a.compressed,size:a.evicted?a.size??0:a.content.length}}let o=i;return{type:"directory",name:s,path:r,mode:o.mode,createdAt:new Date(o.createdAt),updatedAt:new Date(o.updatedAt),childrenCount:o._childCount}}list(t="/"){let e=this.resolveMount(t);if(e){if(!rt.existsSync(e.fullHostPath))return[];try{return rt.readdirSync(e.fullHostPath).sort()}catch{return[]}}let r=ft(t),i=Kt(this.root,r);if(i.type!=="directory")throw new Error(`Cannot list '${t}': not a directory.`);return Object.keys(i.children).sort()}tree(t="/"){let e=ft(t),r=Kt(this.root,e);if(r.type!=="directory")throw new Error(`Cannot render tree for '${t}': not a directory.`);let i=t==="/"?"/":tn.posix.basename(e);return this.renderTreeLines(r,i)}renderTreeLines(t,e){let r=[e],i=Object.keys(t.children).sort();for(let s=0;s<i.length;s++){let o=i[s],a=t.children[o],c=s===i.length-1,l=c?"\u2514\u2500\u2500 ":"\u251C\u2500\u2500 ",u=c?" ":"\u2502 ";if(r.push(`${l}${o}`),a.type==="directory"){let f=this.renderTreeLines(a,"").split(`
1046
1046
  `).slice(1).map(h=>`${u}${h}`);r.push(...f)}}return r.join(`
1047
- `)}getUsageBytes(t="/"){return this.computeUsage(Kt(this.root,ft(t)))}computeUsage(t){if(t.type==="file")return t.content.length;if(t.type==="stub")return t.stubContent.length;let e=0;for(let r of Object.values(t.children))e+=this.computeUsage(r);return e}compressFile(t){let e=Kt(this.root,ft(t));if(e.type!=="file")throw new Error(`Cannot compress '${t}': not a file.`);let r=e;r.compressed||(r.content=(0,Er.gzipSync)(r.content),r.compressed=!0,r.updatedAt=Date.now())}decompressFile(t){let e=Kt(this.root,ft(t));if(e.type!=="file")throw new Error(`Cannot decompress '${t}': not a file.`);let r=e;r.compressed&&(r.content=(0,Er.gunzipSync)(r.content),r.compressed=!1,r.updatedAt=Date.now())}symlink(t,e){let r=ft(e),s=t.startsWith("/")?ft(t):t,{parent:i,name:o}=yr(this.root,r,!0,c=>this.mkdirRecursive(c,493)),a={type:"file",name:o,content:Buffer.from(s,"utf8"),mode:41471,compressed:!1,createdAt:Date.now(),updatedAt:Date.now()};i.children[o]=a,i._childCount++,this._journal({op:ut.SYMLINK,path:r,dest:s}),this.emit("symlink:create",{link:r,target:s})}isSymlink(t){try{let e=Kt(this.root,ft(t));return e.type==="file"&&e.mode===41471}catch{return!1}}resolveSymlink(t,e=8){let r=ft(t);for(let s=0;s<e;s++){try{let i=Kt(this.root,r);if(i.type==="file"&&i.mode===41471){let o=i.content.toString("utf8");r=o.startsWith("/")?o:ft(tn.posix.join(tn.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(!rt.existsSync(r.fullHostPath))throw new Error(`ENOENT: no such file or directory, unlink '${r.fullHostPath}'`);rt.statSync(r.fullHostPath).isDirectory()?rt.rmSync(r.fullHostPath,{recursive:e.recursive??!1}):rt.unlinkSync(r.fullHostPath);return}let s=ft(t);if(s==="/")throw new Error("Cannot remove root directory.");let i=Kt(this.root,s);if(i.type==="directory"){let c=i;if(!e.recursive&&c._childCount>0)throw new Error(`Directory '${s}' is not empty. Use recursive option.`)}let{parent:o,name:a}=yr(this.root,s,!1,()=>{});delete o.children[a],o._childCount--,this.emit("node:remove",{path:s}),this._journal({op:ut.REMOVE,path:s})}move(t,e){let r=ft(t),s=ft(e);if(r==="/"||s==="/")throw new Error("Cannot move root directory.");let i=Kt(this.root,r);if(this.exists(s))throw new Error(`Destination '${s}' already exists.`);this.mkdirRecursive(tn.posix.dirname(s),493);let{parent:o,name:a}=yr(this.root,s,!1,()=>{}),{parent:c,name:l}=yr(this.root,r,!1,()=>{});delete c.children[l],c._childCount--,i.name=a,o.children[a]=i,o._childCount++,this._journal({op:ut.MOVE,path:r,dest:s})}toSnapshot(){return{root:this.serializeDir(this.root)}}serializeDir(t){let e=[];for(let r of Object.values(t.children))r.type==="stub"?e.push({type:"file",name:r.name,mode:r.mode,createdAt:new Date(r.createdAt).toISOString(),updatedAt:new Date(r.updatedAt).toISOString(),compressed:!1,contentBase64:Buffer.from(r.stubContent,"utf8").toString("base64")}):r.type==="file"?e.push(this.serializeFile(r)):e.push(this.serializeDir(r));return{type:"directory",name:t.name,mode:t.mode,createdAt:new Date(t.createdAt).toISOString(),updatedAt:new Date(t.updatedAt).toISOString(),children:e}}serializeFile(t){return{type:"file",name:t.name,mode:t.mode,createdAt:new Date(t.createdAt).toISOString(),updatedAt:new Date(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:Date.parse(t.createdAt),updatedAt:Date.parse(t.updatedAt),children:Object.create(null),_childCount:0};for(let s of t.children){if(s.type==="file"){let i=s;r.children[i.name]={type:"file",name:i.name,mode:i.mode,createdAt:Date.parse(i.createdAt),updatedAt:Date.parse(i.updatedAt),compressed:i.compressed,content:Buffer.from(i.contentBase64,"base64")}}else{let i=this.deserializeDir(s,s.name);r.children[s.name]=i}r._childCount++}return r}},io=Cc;function M(n,t,e=493){n.exists(t)||n.mkdir(t,e)}function T(n,t,e,r=420){n.writeStub(t,e,r)}function ue(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){M(n,"/etc"),T(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=nyx",'VERSION_ID="24.04"',"FORTUNE_CODENAME=nyx"].join(`
1047
+ `)}getUsageBytes(t="/"){return this.computeUsage(Kt(this.root,ft(t)))}computeUsage(t){if(t.type==="file")return t.content.length;if(t.type==="stub")return t.stubContent.length;let e=0;for(let r of Object.values(t.children))e+=this.computeUsage(r);return e}compressFile(t){let e=Kt(this.root,ft(t));if(e.type!=="file")throw new Error(`Cannot compress '${t}': not a file.`);let r=e;r.compressed||(r.content=(0,_r.gzipSync)(r.content),r.compressed=!0,r.updatedAt=Date.now())}decompressFile(t){let e=Kt(this.root,ft(t));if(e.type!=="file")throw new Error(`Cannot decompress '${t}': not a file.`);let r=e;r.compressed&&(r.content=(0,_r.gunzipSync)(r.content),r.compressed=!1,r.updatedAt=Date.now())}symlink(t,e){let r=ft(e),i=t.startsWith("/")?ft(t):t,{parent:s,name:o}=Er(this.root,r,!0,c=>this.mkdirRecursive(c,493)),a={type:"file",name:o,content:Buffer.from(i,"utf8"),mode:41471,compressed:!1,createdAt:Date.now(),updatedAt:Date.now()};s.children[o]=a,s._childCount++,this._journal({op:ut.SYMLINK,path:r,dest:i}),this.emit("symlink:create",{link:r,target:i})}isSymlink(t){try{let e=Kt(this.root,ft(t));return e.type==="file"&&e.mode===41471}catch{return!1}}resolveSymlink(t,e=8){let r=ft(t);for(let i=0;i<e;i++){try{let s=Kt(this.root,r);if(s.type==="file"&&s.mode===41471){let o=s.content.toString("utf8");r=o.startsWith("/")?o:ft(tn.posix.join(tn.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(!rt.existsSync(r.fullHostPath))throw new Error(`ENOENT: no such file or directory, unlink '${r.fullHostPath}'`);rt.statSync(r.fullHostPath).isDirectory()?rt.rmSync(r.fullHostPath,{recursive:e.recursive??!1}):rt.unlinkSync(r.fullHostPath);return}let i=ft(t);if(i==="/")throw new Error("Cannot remove root directory.");let s=Kt(this.root,i);if(s.type==="directory"){let c=s;if(!e.recursive&&c._childCount>0)throw new Error(`Directory '${i}' is not empty. Use recursive option.`)}let{parent:o,name:a}=Er(this.root,i,!1,()=>{});delete o.children[a],o._childCount--,this.emit("node:remove",{path:i}),this._journal({op:ut.REMOVE,path:i})}move(t,e){let r=ft(t),i=ft(e);if(r==="/"||i==="/")throw new Error("Cannot move root directory.");let s=Kt(this.root,r);if(this.exists(i))throw new Error(`Destination '${i}' already exists.`);this.mkdirRecursive(tn.posix.dirname(i),493);let{parent:o,name:a}=Er(this.root,i,!1,()=>{}),{parent:c,name:l}=Er(this.root,r,!1,()=>{});delete c.children[l],c._childCount--,s.name=a,o.children[a]=s,o._childCount++,this._journal({op:ut.MOVE,path:r,dest:i})}toSnapshot(){return{root:this.serializeDir(this.root)}}serializeDir(t){let e=[];for(let r of Object.values(t.children))r.type==="stub"?e.push({type:"file",name:r.name,mode:r.mode,createdAt:new Date(r.createdAt).toISOString(),updatedAt:new Date(r.updatedAt).toISOString(),compressed:!1,contentBase64:Buffer.from(r.stubContent,"utf8").toString("base64")}):r.type==="file"?e.push(this.serializeFile(r)):e.push(this.serializeDir(r));return{type:"directory",name:t.name,mode:t.mode,createdAt:new Date(t.createdAt).toISOString(),updatedAt:new Date(t.updatedAt).toISOString(),children:e}}serializeFile(t){return{type:"file",name:t.name,mode:t.mode,createdAt:new Date(t.createdAt).toISOString(),updatedAt:new Date(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:Date.parse(t.createdAt),updatedAt:Date.parse(t.updatedAt),children:Object.create(null),_childCount:0};for(let i of t.children){if(i.type==="file"){let s=i;r.children[s.name]={type:"file",name:s.name,mode:s.mode,createdAt:Date.parse(s.createdAt),updatedAt:Date.parse(s.updatedAt),compressed:s.compressed,content:Buffer.from(s.contentBase64,"base64")}}else{let s=this.deserializeDir(i,i.name);r.children[i.name]=s}r._childCount++}return r}},oo=vc;function M(n,t,e=493){n.exists(t)||n.mkdir(t,e)}function T(n,t,e,r=420){n.writeStub(t,e,r)}function ue(n,t,e){n.writeFile(t,e)}function Cy(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 ky(n,t,e){M(n,"/etc"),T(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=nyx",'VERSION_ID="24.04"',"FORTUNE_CODENAME=nyx"].join(`
1048
1048
  `)}
1049
1049
  `),T(n,"/etc/debian_version",`nyx/stable
1050
1050
  `),T(n,"/etc/hostname",`${t}
@@ -1130,7 +1130,7 @@ root ALL=(ALL:ALL) ALL
1130
1130
  `),T(n,"/etc/skel/.bash_logout",`# ~/.bash_logout
1131
1131
  `),T(n,"/etc/skel/.profile",`# ~/.profile
1132
1132
  [ -n "$BASH_VERSION" ] && [ -f "$HOME/.bashrc" ] && . "$HOME/.bashrc"
1133
- `),M(n,"/etc/alternatives");let r=[["python3","/usr/bin/python3.12"],["python","/usr/bin/python3.12"],["editor","/usr/bin/nano"],["vi","/usr/bin/nano"],["cc","/usr/bin/gcc"],["gcc","/usr/bin/gcc-13"],["g++","/usr/bin/g++-13"],["java","/usr/lib/jvm/java-21-openjdk-amd64/bin/java"],["node","/usr/bin/node"],["npm","/usr/bin/npm"],["awk","/usr/bin/mawk"],["pager","/usr/bin/less"]];for(let[s,i]of r)T(n,`/etc/alternatives/${s}`,i);M(n,"/etc/java-21-openjdk"),M(n,"/etc/java-21-openjdk/security"),T(n,"/etc/java-21-openjdk/security/java.security",`# java.security
1133
+ `),M(n,"/etc/alternatives");let r=[["python3","/usr/bin/python3.12"],["python","/usr/bin/python3.12"],["editor","/usr/bin/nano"],["vi","/usr/bin/nano"],["cc","/usr/bin/gcc"],["gcc","/usr/bin/gcc-13"],["g++","/usr/bin/g++-13"],["java","/usr/lib/jvm/java-21-openjdk-amd64/bin/java"],["node","/usr/bin/node"],["npm","/usr/bin/npm"],["awk","/usr/bin/mawk"],["pager","/usr/bin/less"]];for(let[i,s]of r)T(n,`/etc/alternatives/${i}`,s);M(n,"/etc/java-21-openjdk"),M(n,"/etc/java-21-openjdk/security"),T(n,"/etc/java-21-openjdk/security/java.security",`# java.security
1134
1134
  `),T(n,"/etc/java-21-openjdk/logging.properties",`# logging.properties
1135
1135
  `),T(n,"/etc/bash.bashrc",`# System-wide .bashrc
1136
1136
  [ -z "$PS1" ] && return
@@ -1157,13 +1157,13 @@ tcp 6 TCP
1157
1157
  udp 17 UDP
1158
1158
  `),M(n,"/etc/profile.d"),T(n,"/etc/profile.d/01-locale-fix.sh",`[ -z "$LANG" ] && export LANG=en_US.UTF-8
1159
1159
  `),T(n,"/etc/profile.d/apps-bin-path.sh",`export PATH="$PATH:/snap/bin"
1160
- `)}function kc(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","bin:x:2:2:bin:/bin:/usr/sbin/nologin","sys:x:3:3:sys:/dev:/usr/sbin/nologin","sync:x:4:65534:sync:/bin:/bin/sync","games:x:5:60:games:/usr/games:/usr/sbin/nologin","man:x:6:12:man:/var/cache/man:/usr/sbin/nologin","lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin","mail:x:8:8:mail:/var/mail:/usr/sbin/nologin","news:x:9:9:news:/var/spool/news:/usr/sbin/nologin","uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin","proxy:x:13:13:proxy:/bin:/usr/sbin/nologin","www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin","backup:x:34:34:backup:/var/backups:/usr/sbin/nologin","list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin","irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin","_apt:x:42:65534::/nonexistent:/usr/sbin/nologin","nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin","messagebus:x:100:106::/nonexistent:/usr/sbin/nologin","systemd-network:x:998:998:systemd Network Management:/:/usr/sbin/nologin","systemd-resolve:x:999:999:systemd Resolver:/:/usr/sbin/nologin","polkitd:x:997:997:polkit:/nonexistent:/usr/sbin/nologin"],s=1e3;for(let l of e)l!=="root"&&(r.push(`${l}:x:${s}:${s}::/home/${l}:/bin/bash`),s++);n.writeFile("/etc/passwd",`${r.join(`
1160
+ `)}function Nc(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","bin:x:2:2:bin:/bin:/usr/sbin/nologin","sys:x:3:3:sys:/dev:/usr/sbin/nologin","sync:x:4:65534:sync:/bin:/bin/sync","games:x:5:60:games:/usr/games:/usr/sbin/nologin","man:x:6:12:man:/var/cache/man:/usr/sbin/nologin","lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin","mail:x:8:8:mail:/var/mail:/usr/sbin/nologin","news:x:9:9:news:/var/spool/news:/usr/sbin/nologin","uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin","proxy:x:13:13:proxy:/bin:/usr/sbin/nologin","www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin","backup:x:34:34:backup:/var/backups:/usr/sbin/nologin","list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin","irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin","_apt:x:42:65534::/nonexistent:/usr/sbin/nologin","nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin","messagebus:x:100:106::/nonexistent:/usr/sbin/nologin","systemd-network:x:998:998:systemd Network Management:/:/usr/sbin/nologin","systemd-resolve:x:999:999:systemd Resolver:/:/usr/sbin/nologin","polkitd:x:997:997:polkit:/nonexistent:/usr/sbin/nologin"],i=1e3;for(let l of e)l!=="root"&&(r.push(`${l}:x:${i}:${i}::/home/${l}:/bin/bash`),i++);n.writeFile("/etc/passwd",`${r.join(`
1161
1161
  `)}
1162
- `);let i=e.filter(l=>t.isSudoer(l)).join(","),o=e.filter(l=>l!=="root").join(","),a=["root:x:0:","daemon:x:1:","bin:x:2:","sys:x:3:","adm:x:4:syslog","tty:x:5:","disk:x:6:","lp:x:7:","mail:x:8:","news:x:9:","uucp:x:10:","man:x:12:","proxy:x:13:","kmem:x:15:","dialout:x:20:","fax:x:21:","voice:x:22:","cdrom:x:24:","floppy:x:25:","tape:x:26:",`sudo:x:27:${i}`,"audio:x:29:","dip:x:30:","www-data:x:33:","backup:x:34:","operator:x:37:","list:x:38:","irc:x:39:","src:x:40:","_apt:x:42:","shadow:x:42:","utmp:x:43:","video:x:44:","sasl:x:45:","plugdev:x:46:","staff:x:50:","games:x:60:",`users:x:100:${o}`,"nogroup:x:65534:","messagebus:x:106:","systemd-network:x:998:","systemd-resolve:x:999:","polkitd:x:997:"];n.writeFile("/etc/group",`${a.join(`
1162
+ `);let s=e.filter(l=>t.isSudoer(l)).join(","),o=e.filter(l=>l!=="root").join(","),a=["root:x:0:","daemon:x:1:","bin:x:2:","sys:x:3:","adm:x:4:syslog","tty:x:5:","disk:x:6:","lp:x:7:","mail:x:8:","news:x:9:","uucp:x:10:","man:x:12:","proxy:x:13:","kmem:x:15:","dialout:x:20:","fax:x:21:","voice:x:22:","cdrom:x:24:","floppy:x:25:","tape:x:26:",`sudo:x:27:${s}`,"audio:x:29:","dip:x:30:","www-data:x:33:","backup:x:34:","operator:x:37:","list:x:38:","irc:x:39:","src:x:40:","_apt:x:42:","shadow:x:42:","utmp:x:43:","video:x:44:","sasl:x:45:","plugdev:x:46:","staff:x:50:","games:x:60:",`users:x:100:${o}`,"nogroup:x:65534:","messagebus:x:106:","systemd-network:x:998:","systemd-resolve:x:999:","polkitd:x:997:"];n.writeFile("/etc/group",`${a.join(`
1163
1163
  `)}
1164
1164
  `);let c=["root:*:19000:0:99999:7:::","daemon:*:19000:0:99999:7:::","nobody:*:19000:0:99999:7:::","messagebus:*:19000:0:99999:7:::","_apt:*:19000:0:99999:7:::","systemd-network:!:19000:::::::","systemd-resolve:!:19000:::::::","polkitd:!:19000:::::::"];for(let l of e)l!=="root"&&c.push(`${l}:!:19000:0:99999:7:::`);n.writeFile("/etc/shadow",`${c.join(`
1165
1165
  `)}
1166
- `,{mode:416})}function Rh(n){let t=n.match(/(\d+)$/);return 1e3+(t?.[1]?parseInt(t[1],10):0)}function Ph(n,t,e,r,s,i,o){let a=`/proc/${t}`;M(n,a),M(n,`${a}/fd`),M(n,`${a}/fdinfo`),M(n,`${a}/net`);let c=Math.floor((Date.now()-new Date(i).getTime())/1e3),l=s.split(/\s+/)[0]??"bash";ue(n,`${a}/cmdline`,`${s.replace(/\s+/g,"\0")}\0`),ue(n,`${a}/comm`,l),ue(n,`${a}/status`,`${[`Name: ${l}`,"Umask: 0022","State: S (sleeping)",`Tgid: ${t}`,`Pid: ${t}`,"PPid: 1","TracerPid: 0","Uid: 0 0 0 0","Gid: 0 0 0 0","FDSize: 64","Groups:","VmPeak: 20480 kB","VmSize: 16384 kB","VmLck: 0 kB","VmPin: 0 kB","VmHWM: 4096 kB","VmRSS: 4096 kB","RssAnon: 512 kB","RssFile: 3584 kB","RssShmem: 0 kB","VmData: 2048 kB","VmStk: 132 kB","VmExe: 924 kB","VmLib: 2744 kB","VmPTE: 52 kB","VmSwap: 0 kB","Threads: 1","SigQ: 0/31968","SigPnd: 0000000000000000","SigBlk: 0000000000010000","SigIgn: 0000000000380004","SigCgt: 000000004b817efb","CapInh: 0000000000000000","CapPrm: 000001ffffffffff","CapEff: 000001ffffffffff","CapBnd: 000001ffffffffff","CapAmb: 0000000000000000","NoNewPrivs: 0","Seccomp: 0","voluntary_ctxt_switches: 100","nonvoluntary_ctxt_switches: 10"].join(`
1166
+ `,{mode:416})}function Th(n){let t=n.match(/(\d+)$/);return 1e3+(t?.[1]?parseInt(t[1],10):0)}function Oh(n,t,e,r,i,s,o){let a=`/proc/${t}`;M(n,a),M(n,`${a}/fd`),M(n,`${a}/fdinfo`),M(n,`${a}/net`);let c=Math.floor((Date.now()-new Date(s).getTime())/1e3),l=i.split(/\s+/)[0]??"bash";ue(n,`${a}/cmdline`,`${i.replace(/\s+/g,"\0")}\0`),ue(n,`${a}/comm`,l),ue(n,`${a}/status`,`${[`Name: ${l}`,"Umask: 0022","State: S (sleeping)",`Tgid: ${t}`,`Pid: ${t}`,"PPid: 1","TracerPid: 0","Uid: 0 0 0 0","Gid: 0 0 0 0","FDSize: 64","Groups:","VmPeak: 20480 kB","VmSize: 16384 kB","VmLck: 0 kB","VmPin: 0 kB","VmHWM: 4096 kB","VmRSS: 4096 kB","RssAnon: 512 kB","RssFile: 3584 kB","RssShmem: 0 kB","VmData: 2048 kB","VmStk: 132 kB","VmExe: 924 kB","VmLib: 2744 kB","VmPTE: 52 kB","VmSwap: 0 kB","Threads: 1","SigQ: 0/31968","SigPnd: 0000000000000000","SigBlk: 0000000000010000","SigIgn: 0000000000380004","SigCgt: 000000004b817efb","CapInh: 0000000000000000","CapPrm: 000001ffffffffff","CapEff: 000001ffffffffff","CapBnd: 000001ffffffffff","CapAmb: 0000000000000000","NoNewPrivs: 0","Seccomp: 0","voluntary_ctxt_switches: 100","nonvoluntary_ctxt_switches: 10"].join(`
1167
1167
  `)}
1168
1168
  `),ue(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 16777216 4096 18446744073709551615 93824992235520 93824992290000 140737488347024 0 0 0 65536 3686404 1266761467 1 0 0 17 0 0 0 0 0 0
1169
1169
  `),ue(n,`${a}/statm`,`4096 1024 768 231 0 512 0
@@ -1189,17 +1189,17 @@ cancelled_write_bytes: 0
1189
1189
  `);for(let u of["0","1","2"])T(n,`${a}/fd/${u}`,""),T(n,`${a}/fdinfo/${u}`,`pos: 0
1190
1190
  flags: 0${u==="0"?"2":"1"}02
1191
1191
  mnt_id: 13
1192
- `)}function Iy(n,t){M(n,"/proc/boot"),T(n,"/proc/boot/log",`${[`[ 0.000000] Linux version ${t.kernel} (fortune@build) #1 SMP PREEMPT_DYNAMIC`,"[ 0.000000] Command line: console=ttyS0 reboot=k panic=1 nomodule random.trust_cpu=1 ipv6.disable=1","[ 0.000060] BIOS-provided physical RAM map:","[ 0.000070] ACPI: RSDP 0x00000000000F05B0 000014 (v00 BOCHS )","[ 0.000120] PCI: Using configuration type 1 for base access","[ 0.000240] clocksource: tsc-early: mask: 0xffffffffffffffff","[ 0.000320] ACPI: IRQ0 used by override","[ 0.000420] Initializing cgroup subsys cpuset","[ 0.000440] Initializing cgroup subsys cpu","[ 0.000450] Initializing cgroup subsys cpuacct","[ 0.000460] Linux agpgart interface v0.103","[ 0.000480] PCI: pci_cache_line_size set to 64 bytes","[ 0.000510] virtio-pci 0000:00:01.0: runtime IRQs not yet assigned","[ 0.000680] NET: Registered PF_INET6 protocol family","[ 0.000720] Freeing unused kernel image (initmem) memory","[ 0.000760] Write protecting the kernel read-only data","[ 0.000800] Run /sbin/init as init process","[ 0.001200] systemd[1]: Detected virtualization kvm","[ 0.001300] systemd[1]: Detected architecture x86-64","[ 0.002000] systemd[1]: Starting Fortune GNU/Linux...","[ 0.003000] systemd[1]: Started Journal Service","[ 0.010000] EXT4-fs (vda): mounted filesystem","[ 0.020000] systemd[1]: Reached target Basic System","[ 0.030000] systemd[1]: Started Login Service"].join(`
1192
+ `)}function vy(n,t){M(n,"/proc/boot"),T(n,"/proc/boot/log",`${[`[ 0.000000] Linux version ${t.kernel} (fortune@build) #1 SMP PREEMPT_DYNAMIC`,"[ 0.000000] Command line: console=ttyS0 reboot=k panic=1 nomodule random.trust_cpu=1 ipv6.disable=1","[ 0.000060] BIOS-provided physical RAM map:","[ 0.000070] ACPI: RSDP 0x00000000000F05B0 000014 (v00 BOCHS )","[ 0.000120] PCI: Using configuration type 1 for base access","[ 0.000240] clocksource: tsc-early: mask: 0xffffffffffffffff","[ 0.000320] ACPI: IRQ0 used by override","[ 0.000420] Initializing cgroup subsys cpuset","[ 0.000440] Initializing cgroup subsys cpu","[ 0.000450] Initializing cgroup subsys cpuacct","[ 0.000460] Linux agpgart interface v0.103","[ 0.000480] PCI: pci_cache_line_size set to 64 bytes","[ 0.000510] virtio-pci 0000:00:01.0: runtime IRQs not yet assigned","[ 0.000680] NET: Registered PF_INET6 protocol family","[ 0.000720] Freeing unused kernel image (initmem) memory","[ 0.000760] Write protecting the kernel read-only data","[ 0.000800] Run /sbin/init as init process","[ 0.001200] systemd[1]: Detected virtualization kvm","[ 0.001300] systemd[1]: Detected architecture x86-64","[ 0.002000] systemd[1]: Starting Fortune GNU/Linux...","[ 0.003000] systemd[1]: Started Journal Service","[ 0.010000] EXT4-fs (vda): mounted filesystem","[ 0.020000] systemd[1]: Reached target Basic System","[ 0.030000] systemd[1]: Started Login Service"].join(`
1193
1193
  `)}
1194
1194
  `),T(n,"/proc/boot/version",`Linux ${t.kernel} (virtual)
1195
- `)}function so(n,t,e,r,s=[]){M(n,"/proc");let i=Math.floor((Date.now()-r)/1e3),o=Math.floor(i*.9);ue(n,"/proc/uptime",`${i}.00 ${o}.00
1195
+ `)}function ao(n,t,e,r,i=[]){M(n,"/proc");let s=Math.floor((Date.now()-r)/1e3),o=Math.floor(s*.9);ue(n,"/proc/uptime",`${s}.00 ${o}.00
1196
1196
  `);let a=Math.floor(Tn.totalmem()/1024),c=Math.floor(Tn.freemem()/1024),l=Math.floor(c*.95),u=Math.floor(a*.03),f=Math.floor(a*.08),h=Math.floor(a*.005),p=Math.floor(a*.02),y=Math.floor(a*.001);ue(n,"/proc/meminfo",`${[`MemTotal: ${String(a).padStart(10)} kB`,`MemFree: ${String(c).padStart(10)} kB`,`MemAvailable: ${String(l).padStart(10)} kB`,`Buffers: ${String(u).padStart(10)} kB`,`Cached: ${String(f).padStart(10)} kB`,`SwapCached: ${String(0).padStart(10)} kB`,`Active: ${String(Math.floor((u+f)*1.2)).padStart(10)} kB`,`Inactive: ${String(Math.floor(f*.6)).padStart(10)} kB`,`Active(anon): ${String(Math.floor(a*.001)).padStart(10)} kB`,`Inactive(anon): ${String(Math.floor(a*.006)).padStart(10)} kB`,`Active(file): ${String(Math.floor(f*1.2)).padStart(10)} kB`,`Inactive(file): ${String(Math.floor(f*.6)).padStart(10)} kB`,`Unevictable: ${String(0).padStart(10)} kB`,`Mlocked: ${String(0).padStart(10)} kB`,`SwapTotal: ${String(0).padStart(10)} kB`,`SwapFree: ${String(0).padStart(10)} kB`,`Zswap: ${String(0).padStart(10)} kB`,`Zswapped: ${String(0).padStart(10)} kB`,`Dirty: ${String(Math.floor(Math.random()*64)).padStart(10)} kB`,`Writeback: ${String(0).padStart(10)} kB`,`AnonPages: ${String(Math.floor(a*.001)).padStart(10)} kB`,`Mapped: ${String(Math.floor(f*.4)).padStart(10)} kB`,`Shmem: ${String(h).padStart(10)} kB`,`KReclaimable: ${String(Math.floor(p*.6)).padStart(10)} kB`,`Slab: ${String(p).padStart(10)} kB`,`SReclaimable: ${String(Math.floor(p*.6)).padStart(10)} kB`,`SUnreclaim: ${String(Math.floor(p*.4)).padStart(10)} kB`,`KernelStack: ${String(Math.floor(a*5e-4)).padStart(10)} kB`,`PageTables: ${String(y).padStart(10)} kB`,`NFS_Unstable: ${String(0).padStart(10)} kB`,`Bounce: ${String(0).padStart(10)} kB`,`WritebackTmp: ${String(0).padStart(10)} kB`,`CommitLimit: ${String(Math.floor(a*.5)).padStart(10)} kB`,`Committed_AS: ${String(Math.floor(a*.05)).padStart(10)} kB`,`VmallocTotal: ${String(35184372087808/1024).padStart(10)} kB`,`VmallocUsed: ${String(Math.floor(a*.01)).padStart(10)} kB`,`VmallocChunk: ${String(0).padStart(10)} kB`,`Percpu: ${String(Math.floor(a*1e-4)).padStart(10)} kB`,`HardwareCorrupted: ${String(0).padStart(6)} kB`,`AnonHugePages: ${String(0).padStart(10)} kB`,`ShmemHugePages: ${String(0).padStart(10)} kB`,`ShmemPmdMapped: ${String(0).padStart(10)} kB`,`FileHugePages: ${String(0).padStart(10)} kB`,`FilePmdMapped: ${String(0).padStart(10)} kB`,`HugePages_Total: ${String(0).padStart(8)}`,`HugePages_Free: ${String(0).padStart(8)}`,`HugePages_Rsvd: ${String(0).padStart(8)}`,`HugePages_Surp: ${String(0).padStart(8)}`,`Hugepagesize: ${String(2048).padStart(10)} kB`,`Hugetlb: ${String(0).padStart(10)} kB`,`DirectMap4k: ${String(Math.floor(a*.02)).padStart(10)} kB`,`DirectMap2M: ${String(Math.floor(a*.98)).padStart(10)} kB`].join(`
1197
1197
  `)}
1198
1198
  `);let E=Tn.cpus(),S=[];for(let F=0;F<E.length;F++){let v=E[F];v&&S.push(`processor : ${F}`,"vendor_id : GenuineIntel","cpu family : 6","model : 85",`model name : ${v.model}`,"stepping : 7","microcode : 0x1",`cpu MHz : ${v.speed.toFixed(3)}`,"cache size : 33792 KB","physical id : 0",`siblings : ${E.length}`,`core id : ${F}`,`cpu cores : ${E.length}`,`apicid : ${F}`,`initial apicid : ${F}`,"fpu : yes","fpu_exception : yes","cpuid level : 13","wp : yes","flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves arat umip avx512_vnni md_clear arch_capabilities","bugs : spectre_v1 spectre_v2 spec_store_bypass swapgs taa mmio_stale_data retbleed eibrs_pbrsb bhi ibpb_no_ret spectre_v2_user its",`bogomips : ${(v.speed*2/1e3).toFixed(2)}`,"clflush size : 64","cache_alignment : 64","address sizes : 46 bits physical, 48 bits virtual","power management:","")}ue(n,"/proc/cpuinfo",`${S.join(`
1199
1199
  `)}
1200
1200
  `),ue(n,"/proc/version",`Linux version ${t.kernel} (fortune@nyx-build) (gcc (Fortune 13.3.0-nyx1) 13.3.0, GNU ld (GNU Binutils for Fortune) 2.42) #2 SMP PREEMPT_DYNAMIC
1201
1201
  `),ue(n,"/proc/hostname",`${e}
1202
- `);let x=(Math.random()*.3).toFixed(2),P=1+s.length;ue(n,"/proc/loadavg",`${x} ${x} ${x} ${P}/${P} 1
1202
+ `);let x=(Math.random()*.3).toFixed(2),P=1+i.length;ue(n,"/proc/loadavg",`${x} ${x} ${x} ${P}/${P} 1
1203
1203
  `),ue(n,"/proc/cmdline",`console=ttyS0 reboot=k panic=1 nomodule random.trust_cpu=1 ipv6.disable=1 swiotlb=noforce rdinit=/process_api init_on_free=1 -- --firecracker-init --addr 0.0.0.0:2024 --max-ws-buffer-size 32768 --block-local-connections
1204
1204
  `),ue(n,"/proc/filesystems",`${["nodev sysfs","nodev tmpfs","nodev bdev","nodev proc","nodev cgroup","nodev cgroup2","nodev cpuset","nodev devtmpfs","nodev binfmt_misc","nodev debugfs","nodev securityfs","nodev sockfs","nodev bpf","nodev pipefs","nodev ramfs","nodev hugetlbfs","nodev rpc_pipefs","nodev devpts"," ext3"," ext2"," ext4"," squashfs","nodev nfs","nodev nfs4","nodev autofs"," fuseblk","nodev fuse","nodev fusectl","nodev overlay"," xfs","nodev mqueue","nodev selinuxfs","nodev pstore"].join(`
1205
1205
  `)}
@@ -1230,7 +1230,7 @@ FRAG: inuse 0 memory 0
1230
1230
  `),ue(n,"/proc/diskstats",`${[" 254 0 vda 1000 0 8000 500 200 0 1600 100 0 600 600 0 0 0 0"," 254 16 vdb 100 0 800 50 0 0 0 0 0 50 50 0 0 0 0"," 254 32 vdc 50 0 400 25 0 0 0 0 0 25 25 0 0 0 0"," 254 48 vdd 80 0 640 40 0 0 0 0 0 40 40 0 0 0 0"].join(`
1231
1231
  `)}
1232
1232
  `),ue(n,"/proc/interrupts",` CPU0
1233
- 0: ${Math.floor(i*250)} IO-APIC 2-edge timer
1233
+ 0: ${Math.floor(s*250)} IO-APIC 2-edge timer
1234
1234
  1: 9 IO-APIC 1-edge i8042
1235
1235
  NMI: 0 Non-maskable interrupts
1236
1236
  ERR: 0
@@ -1278,11 +1278,11 @@ FRAG: inuse 0 memory 0
1278
1278
  `),ue(n,"/proc/sys/fs/inotify/max_queued_events",`16384
1279
1279
  `),ue(n,"/proc/cgroups",`${["#subsys_name hierarchy num_cgroups enabled","cpuset 5 1 1","cpu 1 1 1","cpuacct 2 1 1","blkio 6 1 1","memory 3 1 1","devices 4 1 1","freezer 7 1 1","pids 8 1 1"].join(`
1280
1280
  `)}
1281
- `),Ph(n,1,"root","pts/0","/sbin/init",new Date(r).toISOString(),{});for(let F of s){let v=Rh(F.tty);Ph(n,v,F.username,F.tty,"bash",F.startedAt,{USER:F.username,HOME:`/home/${F.username}`,TERM:"xterm-256color",SHELL:"/bin/bash",LANG:"en_US.UTF-8",PATH:"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",LOGNAME:F.username})}let C=s.length>0?Rh(s[s.length-1].tty):1;try{n.remove("/proc/self")}catch{}let $=`/proc/${C}`;if(M(n,"/proc/self"),M(n,"/proc/self/fd"),M(n,"/proc/self/fdinfo"),M(n,"/proc/self/net"),n.exists($))for(let F of n.list($)){let v=`${$}/${F}`,b=`/proc/self/${F}`;try{n.stat(v).type==="file"&&ue(n,b,n.readFile(v))}catch{}}else ue(n,"/proc/self/cmdline","bash\0"),ue(n,"/proc/self/comm","bash"),ue(n,"/proc/self/status",`Name: bash
1281
+ `),Oh(n,1,"root","pts/0","/sbin/init",new Date(r).toISOString(),{});for(let F of i){let v=Th(F.tty);Oh(n,v,F.username,F.tty,"bash",F.startedAt,{USER:F.username,HOME:`/home/${F.username}`,TERM:"xterm-256color",SHELL:"/bin/bash",LANG:"en_US.UTF-8",PATH:"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",LOGNAME:F.username})}let C=i.length>0?Th(i[i.length-1].tty):1;try{n.remove("/proc/self")}catch{}let $=`/proc/${C}`;if(M(n,"/proc/self"),M(n,"/proc/self/fd"),M(n,"/proc/self/fdinfo"),M(n,"/proc/self/net"),n.exists($))for(let F of n.list($)){let v=`${$}/${F}`,b=`/proc/self/${F}`;try{n.stat(v).type==="file"&&ue(n,b,n.readFile(v))}catch{}}else ue(n,"/proc/self/cmdline","bash\0"),ue(n,"/proc/self/comm","bash"),ue(n,"/proc/self/status",`Name: bash
1282
1282
  State: S (sleeping)
1283
1283
  Pid: 1
1284
1284
  PPid: 0
1285
- `),ue(n,"/proc/self/environ",""),ue(n,"/proc/self/cwd","/root\0"),ue(n,"/proc/self/exe","/bin/bash\0")}function Cy(n,t,e){M(n,"/sys"),M(n,"/sys/devices"),M(n,"/sys/devices/virtual"),M(n,"/sys/devices/system"),M(n,"/sys/devices/system/cpu"),M(n,"/sys/devices/system/cpu/cpu0"),T(n,"/sys/devices/system/cpu/cpu0/online",`1
1285
+ `),ue(n,"/proc/self/environ",""),ue(n,"/proc/self/cwd","/root\0"),ue(n,"/proc/self/exe","/bin/bash\0")}function Ny(n,t,e){M(n,"/sys"),M(n,"/sys/devices"),M(n,"/sys/devices/virtual"),M(n,"/sys/devices/system"),M(n,"/sys/devices/system/cpu"),M(n,"/sys/devices/system/cpu/cpu0"),T(n,"/sys/devices/system/cpu/cpu0/online",`1
1286
1286
  `),T(n,"/sys/devices/system/cpu/online",`0
1287
1287
  `),T(n,"/sys/devices/system/cpu/possible",`0
1288
1288
  `),T(n,"/sys/devices/system/cpu/present",`0
@@ -1294,7 +1294,7 @@ PPid: 0
1294
1294
  `),T(n,"/sys/class/net/eth0/duplex",`full
1295
1295
  `),T(n,"/sys/class/net/eth0/address",`aa:bb:cc:dd:ee:ff
1296
1296
  `),T(n,"/sys/class/net/eth0/tx_queue_len",`1000
1297
- `);let r=xy(t),s=r.toString(16).padStart(8,"0");T(n,"/sys/class/net/eth0/address",`52:54:00:${s.slice(0,2)}:${s.slice(2,4)}:${s.slice(4,6)}
1297
+ `);let r=Cy(t),i=r.toString(16).padStart(8,"0");T(n,"/sys/class/net/eth0/address",`52:54:00:${i.slice(0,2)}:${i.slice(2,4)}:${i.slice(4,6)}
1298
1298
  `),M(n,"/sys/class/net/lo"),T(n,"/sys/class/net/lo/operstate",`unknown
1299
1299
  `),T(n,"/sys/class/net/lo/carrier",`1
1300
1300
  `),T(n,"/sys/class/net/lo/mtu",`65536
@@ -1313,11 +1313,11 @@ PPid: 0
1313
1313
  `),M(n,"/sys/kernel"),T(n,"/sys/kernel/hostname",`${t}
1314
1314
  `),T(n,"/sys/kernel/osrelease",`${e.kernel}
1315
1315
  `),T(n,"/sys/kernel/ostype",`Linux
1316
- `),M(n,"/sys/kernel/security"),M(n,"/sys/devices/virtual"),M(n,"/sys/devices/virtual/dmi"),M(n,"/sys/devices/virtual/dmi/id");let i=`VirtualNode-${(r%1e4).toString().padStart(4,"0")}`,o={bios_vendor:"Virtual BIOS",bios_version:"1.0",bios_date:"01/01/2025",sys_vendor:"Fortune Systems",product_name:i,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${i}`};for(let[a,c]of Object.entries(o))T(n,`/sys/devices/virtual/dmi/id/${a}`,`${c}
1316
+ `),M(n,"/sys/kernel/security"),M(n,"/sys/devices/virtual"),M(n,"/sys/devices/virtual/dmi"),M(n,"/sys/devices/virtual/dmi/id");let s=`VirtualNode-${(r%1e4).toString().padStart(4,"0")}`,o={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[a,c]of Object.entries(o))T(n,`/sys/devices/virtual/dmi/id/${a}`,`${c}
1317
1317
  `);M(n,"/sys/class"),M(n,"/sys/class/net"),M(n,"/sys/kernel"),T(n,"/sys/kernel/hostname",`${t}
1318
1318
  `),T(n,"/sys/kernel/osrelease",`${e.kernel}
1319
1319
  `),T(n,"/sys/kernel/ostype",`Linux
1320
- `)}function ky(n){M(n,"/dev"),T(n,"/dev/null","",438),T(n,"/dev/zero","",438),T(n,"/dev/full","",438),T(n,"/dev/random","",292),T(n,"/dev/urandom","",292),T(n,"/dev/mem","",416),T(n,"/dev/port","",416),T(n,"/dev/kmsg","",432),T(n,"/dev/hwrng","",432),T(n,"/dev/fuse","",432),T(n,"/dev/autofs","",432),T(n,"/dev/userfaultfd","",432),T(n,"/dev/cpu_dma_latency","",432),T(n,"/dev/ptp0","",432),T(n,"/dev/snapshot","",432),T(n,"/dev/console","",384),T(n,"/dev/tty","",438),T(n,"/dev/ttyS0","",432),T(n,"/dev/ptmx","",438);for(let t=0;t<=63;t++)T(n,`/dev/tty${t}`,"",400);T(n,"/dev/vcs","",400),T(n,"/dev/vcs1","",400),T(n,"/dev/vcsa","",400),T(n,"/dev/vcsa1","",400),T(n,"/dev/vcsu","",400),T(n,"/dev/vcsu1","",400);for(let t=0;t<8;t++)T(n,`/dev/loop${t}`,"",432);M(n,"/dev/loop-control"),T(n,"/dev/vda","",432),T(n,"/dev/vdb","",432),T(n,"/dev/vdc","",432),T(n,"/dev/vdd","",432),M(n,"/dev/net"),T(n,"/dev/net/tun","",432),M(n,"/dev/pts"),M(n,"/dev/shm"),M(n,"/dev/cpu"),T(n,"/dev/stdin","",438),T(n,"/dev/stdout","",438),T(n,"/dev/stderr","",438),M(n,"/dev/fd"),T(n,"/dev/vga_arbiter","",432),T(n,"/dev/vsock","",432)}function vy(n){M(n,"/usr"),M(n,"/usr/bin"),M(n,"/usr/sbin"),M(n,"/usr/local"),M(n,"/usr/local/bin"),M(n,"/usr/local/lib"),M(n,"/usr/local/share"),M(n,"/usr/local/include"),M(n,"/usr/local/sbin"),M(n,"/usr/share"),M(n,"/usr/share/doc"),M(n,"/usr/share/man"),M(n,"/usr/share/man/man1"),M(n,"/usr/share/man/man5"),M(n,"/usr/share/man/man8"),M(n,"/usr/share/common-licenses"),M(n,"/usr/share/ca-certificates"),M(n,"/usr/share/zoneinfo"),M(n,"/usr/lib"),M(n,"/usr/lib/x86_64-linux-gnu"),M(n,"/usr/lib/python3"),M(n,"/usr/lib/python3/dist-packages"),M(n,"/usr/lib/python3.12"),M(n,"/usr/lib/jvm"),M(n,"/usr/lib/jvm/java-21-openjdk-amd64"),M(n,"/usr/lib/jvm/java-21-openjdk-amd64/bin"),M(n,"/usr/lib/node_modules"),M(n,"/usr/lib/node_modules/npm"),M(n,"/usr/include"),M(n,"/usr/src");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 r of t)T(n,`/usr/bin/${r}`,`#!/bin/sh
1320
+ `)}function By(n){M(n,"/dev"),T(n,"/dev/null","",438),T(n,"/dev/zero","",438),T(n,"/dev/full","",438),T(n,"/dev/random","",292),T(n,"/dev/urandom","",292),T(n,"/dev/mem","",416),T(n,"/dev/port","",416),T(n,"/dev/kmsg","",432),T(n,"/dev/hwrng","",432),T(n,"/dev/fuse","",432),T(n,"/dev/autofs","",432),T(n,"/dev/userfaultfd","",432),T(n,"/dev/cpu_dma_latency","",432),T(n,"/dev/ptp0","",432),T(n,"/dev/snapshot","",432),T(n,"/dev/console","",384),T(n,"/dev/tty","",438),T(n,"/dev/ttyS0","",432),T(n,"/dev/ptmx","",438);for(let t=0;t<=63;t++)T(n,`/dev/tty${t}`,"",400);T(n,"/dev/vcs","",400),T(n,"/dev/vcs1","",400),T(n,"/dev/vcsa","",400),T(n,"/dev/vcsa1","",400),T(n,"/dev/vcsu","",400),T(n,"/dev/vcsu1","",400);for(let t=0;t<8;t++)T(n,`/dev/loop${t}`,"",432);M(n,"/dev/loop-control"),T(n,"/dev/vda","",432),T(n,"/dev/vdb","",432),T(n,"/dev/vdc","",432),T(n,"/dev/vdd","",432),M(n,"/dev/net"),T(n,"/dev/net/tun","",432),M(n,"/dev/pts"),M(n,"/dev/shm"),M(n,"/dev/cpu"),T(n,"/dev/stdin","",438),T(n,"/dev/stdout","",438),T(n,"/dev/stderr","",438),M(n,"/dev/fd"),T(n,"/dev/vga_arbiter","",432),T(n,"/dev/vsock","",432)}function Ry(n){M(n,"/usr"),M(n,"/usr/bin"),M(n,"/usr/sbin"),M(n,"/usr/local"),M(n,"/usr/local/bin"),M(n,"/usr/local/lib"),M(n,"/usr/local/share"),M(n,"/usr/local/include"),M(n,"/usr/local/sbin"),M(n,"/usr/share"),M(n,"/usr/share/doc"),M(n,"/usr/share/man"),M(n,"/usr/share/man/man1"),M(n,"/usr/share/man/man5"),M(n,"/usr/share/man/man8"),M(n,"/usr/share/common-licenses"),M(n,"/usr/share/ca-certificates"),M(n,"/usr/share/zoneinfo"),M(n,"/usr/lib"),M(n,"/usr/lib/x86_64-linux-gnu"),M(n,"/usr/lib/python3"),M(n,"/usr/lib/python3/dist-packages"),M(n,"/usr/lib/python3.12"),M(n,"/usr/lib/jvm"),M(n,"/usr/lib/jvm/java-21-openjdk-amd64"),M(n,"/usr/lib/jvm/java-21-openjdk-amd64/bin"),M(n,"/usr/lib/node_modules"),M(n,"/usr/lib/node_modules/npm"),M(n,"/usr/include"),M(n,"/usr/src");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 r of t)T(n,`/usr/bin/${r}`,`#!/bin/sh
1321
1321
  exec builtin ${r} "$@"
1322
1322
  `,493);let e=["nologin","useradd","userdel","groupadd","groupdel","adduser","deluser","shutdown","reboot","halt","init","service","update-alternatives","update-rc.d","depmod","modprobe","insmod","rmmod","lsmod","ifconfig","route","iptables","ip6tables","arp","iwconfig","ethtool","fdisk","parted","mkfs.ext4","fsck","ldconfig","ldconfig.real"];for(let r of e)T(n,`/usr/sbin/${r}`,`#!/bin/sh
1323
1323
  exec builtin ${r} "$@"
@@ -1340,7 +1340,7 @@ exec javac "$@"
1340
1340
  `),T(n,"/usr/share/common-licenses/LGPL-2.1",`GNU Lesser General Public License v2.1
1341
1341
  `),T(n,"/usr/share/common-licenses/Apache-2.0",`Apache License 2.0
1342
1342
  `),T(n,"/usr/share/common-licenses/MIT",`MIT License
1343
- `)}var Ny=`Package: bash
1343
+ `)}var Py=`Package: bash
1344
1344
  Status: install ok installed
1345
1345
  Priority: required
1346
1346
  Section: shells
@@ -1600,14 +1600,14 @@ Description: pager program similar to more
1600
1600
  This package provides the \`less\` command, which is similar to more but allows
1601
1601
  you to move backwards through the file.
1602
1602
 
1603
- `;function By(n){M(n,"/var"),M(n,"/var/log"),M(n,"/var/log/apt"),M(n,"/var/log/journal"),M(n,"/var/log/private"),M(n,"/var/tmp"),M(n,"/var/cache"),M(n,"/var/cache/apt"),M(n,"/var/cache/apt/archives"),M(n,"/var/cache/apt/archives/partial"),M(n,"/var/cache/debconf"),M(n,"/var/cache/ldconfig"),M(n,"/var/cache/fontconfig"),M(n,"/var/cache/PackageKit"),M(n,"/var/lib"),M(n,"/var/lib/apt"),M(n,"/var/lib/apt/lists"),M(n,"/var/lib/apt/lists/partial"),M(n,"/var/lib/dpkg"),M(n,"/var/lib/dpkg/info"),M(n,"/var/lib/dpkg/updates"),M(n,"/var/lib/dpkg/alternatives"),M(n,"/var/lib/misc"),M(n,"/var/lib/systemd"),M(n,"/var/lib/systemd/coredump"),M(n,"/var/lib/pam"),M(n,"/var/lib/git"),M(n,"/var/lib/PackageKit"),M(n,"/var/lib/python"),M(n,"/var/spool"),M(n,"/var/spool/cron"),M(n,"/var/spool/mail"),M(n,"/var/mail"),M(n,"/var/backups"),M(n,"/var/www"),T(n,"/var/lib/dpkg/status",Ny),T(n,"/var/lib/dpkg/available",""),T(n,"/var/lib/dpkg/lock",""),T(n,"/var/lib/dpkg/lock-frontend",""),T(n,"/var/lib/apt/lists/lock",""),T(n,"/var/cache/apt/pkgcache.bin",""),T(n,"/var/cache/apt/srcpkgcache.bin",""),T(n,"/var/log/syslog",`${new Date().toUTCString()} kernel: Virtual container started
1604
- `),T(n,"/var/log/auth.log",""),T(n,"/var/log/kern.log",""),T(n,"/var/log/dpkg.log",""),T(n,"/var/log/apt/history.log",""),T(n,"/var/log/apt/term.log",""),T(n,"/var/log/faillog",""),T(n,"/var/log/lastlog",""),T(n,"/var/log/wtmp",""),T(n,"/var/log/btmp",""),T(n,"/var/log/alternatives.log",""),M(n,"/run"),M(n,"/run/lock"),M(n,"/run/lock/subsys"),M(n,"/run/systemd"),M(n,"/run/systemd/ask-password"),M(n,"/run/systemd/sessions"),M(n,"/run/systemd/users"),M(n,"/run/user"),M(n,"/run/dbus"),M(n,"/run/adduser"),T(n,"/run/utmp",""),T(n,"/run/dbus/system_bus_socket","")}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"),M(n,"/lib"),M(n,"/lib64"),M(n,"/lib/x86_64-linux-gnu"),M(n,"/lib/modules"),n.exists("/lib64/ld-linux-x86-64.so.2")||T(n,"/lib64/ld-linux-x86-64.so.2","",493)}function Py(n){M(n,"/tmp",1023),M(n,"/tmp/node-compile-cache",1023)}function Ty(n){M(n,"/root",448),M(n,"/root/.ssh",448),M(n,"/root/.config",493),M(n,"/root/.config/pip",493),M(n,"/root/.local",493),M(n,"/root/.local/share",493),T(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","export LANG=en_US.UTF-8","alias ll='ls -la'","alias la='ls -A'","alias l='ls -CF'"].join(`
1603
+ `;function Ty(n){M(n,"/var"),M(n,"/var/log"),M(n,"/var/log/apt"),M(n,"/var/log/journal"),M(n,"/var/log/private"),M(n,"/var/tmp"),M(n,"/var/cache"),M(n,"/var/cache/apt"),M(n,"/var/cache/apt/archives"),M(n,"/var/cache/apt/archives/partial"),M(n,"/var/cache/debconf"),M(n,"/var/cache/ldconfig"),M(n,"/var/cache/fontconfig"),M(n,"/var/cache/PackageKit"),M(n,"/var/lib"),M(n,"/var/lib/apt"),M(n,"/var/lib/apt/lists"),M(n,"/var/lib/apt/lists/partial"),M(n,"/var/lib/dpkg"),M(n,"/var/lib/dpkg/info"),M(n,"/var/lib/dpkg/updates"),M(n,"/var/lib/dpkg/alternatives"),M(n,"/var/lib/misc"),M(n,"/var/lib/systemd"),M(n,"/var/lib/systemd/coredump"),M(n,"/var/lib/pam"),M(n,"/var/lib/git"),M(n,"/var/lib/PackageKit"),M(n,"/var/lib/python"),M(n,"/var/spool"),M(n,"/var/spool/cron"),M(n,"/var/spool/mail"),M(n,"/var/mail"),M(n,"/var/backups"),M(n,"/var/www"),T(n,"/var/lib/dpkg/status",Py),T(n,"/var/lib/dpkg/available",""),T(n,"/var/lib/dpkg/lock",""),T(n,"/var/lib/dpkg/lock-frontend",""),T(n,"/var/lib/apt/lists/lock",""),T(n,"/var/cache/apt/pkgcache.bin",""),T(n,"/var/cache/apt/srcpkgcache.bin",""),T(n,"/var/log/syslog",`${new Date().toUTCString()} kernel: Virtual container started
1604
+ `),T(n,"/var/log/auth.log",""),T(n,"/var/log/kern.log",""),T(n,"/var/log/dpkg.log",""),T(n,"/var/log/apt/history.log",""),T(n,"/var/log/apt/term.log",""),T(n,"/var/log/faillog",""),T(n,"/var/log/lastlog",""),T(n,"/var/log/wtmp",""),T(n,"/var/log/btmp",""),T(n,"/var/log/alternatives.log",""),M(n,"/run"),M(n,"/run/lock"),M(n,"/run/lock/subsys"),M(n,"/run/systemd"),M(n,"/run/systemd/ask-password"),M(n,"/run/systemd/sessions"),M(n,"/run/systemd/users"),M(n,"/run/user"),M(n,"/run/dbus"),M(n,"/run/adduser"),T(n,"/run/utmp",""),T(n,"/run/dbus/system_bus_socket","")}function Oy(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"),M(n,"/lib"),M(n,"/lib64"),M(n,"/lib/x86_64-linux-gnu"),M(n,"/lib/modules"),n.exists("/lib64/ld-linux-x86-64.so.2")||T(n,"/lib64/ld-linux-x86-64.so.2","",493)}function My(n){M(n,"/tmp",1023),M(n,"/tmp/node-compile-cache",1023)}function Ly(n){M(n,"/root",448),M(n,"/root/.ssh",448),M(n,"/root/.config",493),M(n,"/root/.config/pip",493),M(n,"/root/.local",493),M(n,"/root/.local/share",493),T(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","export LANG=en_US.UTF-8","alias ll='ls -la'","alias la='ls -A'","alias l='ls -CF'"].join(`
1605
1605
  `)}
1606
1606
  `),T(n,"/root/.profile",`[ -f ~/.bashrc ] && . ~/.bashrc
1607
1607
  `),T(n,"/root/.bash_logout",`# ~/.bash_logout
1608
1608
  `),T(n,"/root/.config/pip/pip.conf",`[global]
1609
1609
  break-system-packages = true
1610
- `)}function Oy(n,t){M(n,"/opt"),M(n,"/opt/rclone"),M(n,"/srv"),M(n,"/mnt"),M(n,"/media"),M(n,"/boot"),M(n,"/boot/grub"),T(n,"/boot/grub/grub.cfg",`${["# GRUB configuration (virtual)","set default=0","set timeout=0","",'menuentry "Fortune GNU/Linux" {',` linux /vmlinuz-${t.kernel} root=/dev/vda rw console=ttyS0`,` initrd /initrd.img-${t.kernel}`,"}"].join(`
1610
+ `)}function Dy(n,t){M(n,"/opt"),M(n,"/opt/rclone"),M(n,"/srv"),M(n,"/mnt"),M(n,"/media"),M(n,"/boot"),M(n,"/boot/grub"),T(n,"/boot/grub/grub.cfg",`${["# GRUB configuration (virtual)","set default=0","set timeout=0","",'menuentry "Fortune GNU/Linux" {',` linux /vmlinuz-${t.kernel} root=/dev/vda rw console=ttyS0`,` initrd /initrd.img-${t.kernel}`,"}"].join(`
1611
1611
  `)}
1612
1612
  `);let e=t.kernel;T(n,`/boot/vmlinuz-${e}`,"",420),T(n,`/boot/initrd.img-${e}`,"",420),T(n,`/boot/System.map-${e}`,`${e} virtual
1613
1613
  `,420),T(n,`/boot/config-${e}`,`# Linux kernel config ${e}
@@ -1615,22 +1615,18 @@ CONFIG_VIRTIO=y
1615
1615
  CONFIG_VIRTIO_BLK=y
1616
1616
  CONFIG_VIRTIO_NET=y
1617
1617
  CONFIG_KVM_GUEST=y
1618
- `,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"),M(n,"/lost+found",448),M(n,"/home")}var Th=new Map;function My(n,t){return`${n}|${t.kernel}|${t.os}|${t.arch}`}function Ly(n,t){let e=My(n,t),r=Th.get(e);if(r)return r;let s=new io({mode:"memory"});wy(s,n,t),Cy(s,n,t),ky(s),vy(s),By(s),Ry(s),Py(s),Oy(s,t),Iy(s,t);let i=s.encodeBinary();return Th.set(e,i),i}function Oh(n,t,e,r,s,i=[]){let o=Ly(e,r);n.getMode()==="fs"&&n.exists("/home")?n.mergeRootTree(or(o)):n.importRootTree(or(o)),Ty(n),so(n,r,e,s,i),kc(n,t)}function Mh(n){return n==="1"||n==="true"}function Lh(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function Dy(){return Mh(process.env.DEV_MODE)||Mh(process.env.RENDER_PERF)}function ar(n){let t=Dy();if(!t)return{enabled:t,mark:()=>{},done:()=>{}};let e=Lh(),r=i=>{let o=Lh()-e;console.log(`[perf][${n}] ${i}: ${o.toFixed(1)}ms`)};return{enabled:t,mark:r,done:(i="done")=>{r(i)}}}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
1619
- echo 'vim: use nano for editing in this environment'
1620
- `,mode:493},{path:"/usr/bin/vi",content:`#!/bin/sh
1621
- exec vim "$@"
1622
- `,mode:493},{path:"/usr/share/doc/vim/README",content:`Vim editor \u2014 virtual package.
1618
+ `,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"),M(n,"/lost+found",448),M(n,"/home")}var Mh=new Map;function Uy(n,t){return`${n}|${t.kernel}|${t.os}|${t.arch}`}function $y(n,t){let e=Uy(n,t),r=Mh.get(e);if(r)return r;let i=new oo({mode:"memory"});ky(i,n,t),Ny(i,n,t),By(i),Ry(i),Ty(i),Oy(i),My(i),Dy(i,t),vy(i,t);let s=i.encodeBinary();return Mh.set(e,s),s}function Lh(n,t,e,r,i,s=[]){let o=$y(e,r);n.getMode()==="fs"&&n.exists("/home")?n.mergeRootTree(ar(o)):n.importRootTree(ar(o)),Ly(n),ao(n,r,e,i,s),Nc(n,t)}function Dh(n){return n==="1"||n==="true"}function Uh(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function Fy(){return Dh(process.env.DEV_MODE)||Dh(process.env.RENDER_PERF)}function cr(n){let t=Fy();if(!t)return{enabled:t,mark:()=>{},done:()=>{}};let e=Uh(),r=s=>{let o=Uh()-e;console.log(`[perf][${n}] ${s}: ${o.toFixed(1)}ms`)};return{enabled:t,mark:r,done:(s="done")=>{r(s)}}}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/share/doc/vim/README",content:`Vim editor \u2014 virtual package.
1623
1619
  `}]},{name:"git",version:"1:2.39.2-1",section:"vcs",description:"Fast, scalable, distributed revision control system",shortDesc:"fast distributed version control system",installedSizeKb:11240,files:[{path:"/usr/bin/git",content:`#!/bin/sh
1624
1620
  echo 'git: virtual stub \u2014 no host access'
1625
1621
  `,mode:493},{path:"/usr/share/doc/git/README.Debian",content:`Git virtual package for Fortune GNU/Linux.
1626
1622
  `}]},{name:"python3",version:"3.11.2-1+b1",section:"python",description:"Interactive high-level object-oriented language (version 3)",shortDesc:"interactive high-level object-oriented language",installedSizeKb:512,depends:["python3-minimal"],files:[{path:"/usr/bin/python3",content:`#!/bin/sh
1627
1623
  echo 'Python 3.11.2 (virtual)'
1628
1624
  `,mode:493},{path:"/usr/bin/python3.11",content:`#!/bin/sh
1629
- exec python3 "$@"
1625
+ exec builtin python3 "$@"
1630
1626
  `,mode:493},{path:"/usr/lib/python3.11/.keep",content:""}]},{name:"python3-minimal",version:"3.11.2-1+b1",section:"python",description:"Minimal subset of the Python language (version 3)",shortDesc:"minimal subset of Python language",installedSizeKb:196,files:[{path:"/usr/lib/python3-minimal/.keep",content:""}]},{name:"nodejs",version:"18.19.0+dfsg-6",section:"javascript",description:"Evented I/O for V8 javascript - runtime executable",shortDesc:"Node.js JavaScript runtime",installedSizeKb:15360,files:[{path:"/usr/bin/node",content:`#!/bin/sh
1631
1627
  echo 'node v18.19.0 (virtual)'
1632
1628
  `,mode:493},{path:"/usr/bin/nodejs",content:`#!/bin/sh
1633
- exec node "$@"
1629
+ exec builtin node "$@"
1634
1630
  `,mode:493},{path:"/usr/share/doc/nodejs/README",content:`Node.js virtual package.
1635
1631
  `}]},{name:"npm",version:"9.2.0~ds1-2",section:"javascript",description:"package manager for Node.js",shortDesc:"package manager for Node.js",installedSizeKb:9814,depends:["nodejs"],files:[{path:"/usr/bin/npm",content:`#!/bin/sh
1636
1632
  exec builtin npm "$@"
@@ -1672,7 +1668,7 @@ echo 'jq: virtual stub \u2014 pipe JSON here'
1672
1668
  `}]},{name:"gcc",version:"4:12.2.0-3",section:"devel",description:"GNU C compiler",shortDesc:"GNU C compiler",installedSizeKb:24448,files:[{path:"/usr/bin/gcc",content:`#!/bin/sh
1673
1669
  echo 'gcc (Fortune GNU/Linux) 12.2.0 (virtual)'
1674
1670
  `,mode:493},{path:"/usr/bin/gcc-12",content:`#!/bin/sh
1675
- exec gcc "$@"
1671
+ echo 'gcc (Fortune GNU/Linux) 12.2.0 (virtual)'
1676
1672
  `,mode:493}]},{name:"g++",version:"4:12.2.0-3",section:"devel",description:"GNU C++ compiler",shortDesc:"GNU C++ compiler",installedSizeKb:1024,depends:["gcc"],files:[{path:"/usr/bin/g++",content:`#!/bin/sh
1677
1673
  echo 'g++ (Fortune GNU/Linux) 12.2.0 (virtual)'
1678
1674
  `,mode:493}]},{name:"make",version:"4.3-4.1",section:"devel",description:"Utility for directing compilation",shortDesc:"build utility",installedSizeKb:504,files:[{path:"/usr/bin/make",content:`#!/bin/sh
@@ -1704,47 +1700,47 @@ echo 'journalctl: virtual stub'
1704
1700
  echo 'gzip: virtual stub'
1705
1701
  `,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
1706
1702
  echo 'neofetch: virtual stub'
1707
- `,mode:493}]}],oo=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(`
1703
+ `,mode:493}]}],co=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 i=this.parseFields(r),s=i.Package;s&&this.installed.set(s,{name:s,version:i.Version??"unknown",architecture:i.Architecture??"amd64",maintainer:i.Maintainer??"Fortune Maintainers",description:i.Description??"",section:i.Section??"misc",installedSizeKb:Number(i["Installed-Size"]??0),installedAt:i["X-Installed-At"]??new Date().toISOString(),files:(i["X-Files"]??"").split("|").filter(Boolean)})}}persist(){let t=[];for(let e of this.installed.values())t.push([`Package: ${e.name}`,"Status: install ok installed","Priority: optional",`Section: ${e.section}`,`Installed-Size: ${e.installedSizeKb}`,`Maintainer: ${e.maintainer}`,`Architecture: ${e.architecture}`,`Version: ${e.version}`,`Description: ${e.description}`,`X-Installed-At: ${e.installedAt}`,`X-Files: ${e.files.join("|")}`].join(`
1708
1704
  `));this.vfs.writeFile(this.registryPath,`${t.join(`
1709
1705
 
1710
1706
  `)}
1711
1707
  `)}parseFields(t){let e={};for(let r of t.split(`
1712
- `)){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}
1713
- `,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(`
1714
- `);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 u=this.findInRegistry(c);if(!u){i.push(c);return}for(let f of u.depends??[])o(f,l);s.find(f=>f.name===u.name)||s.push(u)};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(`
1715
- `),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 u of c.files??[]){let f=u.path.slice(0,u.path.lastIndexOf("/"));f&&!this.vfs.exists(f)&&this.vfs.mkdir(f,493),this.vfs.writeFile(u.path,u.content,{mode:u.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(u=>u.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(`
1716
- `),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(`
1717
- `)||"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(`
1718
- `),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(`
1719
- `)}};var In=require("node:crypto"),Uh=require("node:events"),$h=Yt(require("node:path"),1);function Uy(){let n=process.env.SSH_MIMIC_FAST_PASSWORD_HASH;return!!n&&!["0","false","no","off"].includes(n.toLowerCase())}var Mt=ar("VirtualUserManager"),ao=class n extends Uh.EventEmitter{constructor(e,r=!0){super();this.vfs=e;this.autoSudoForNewUsers=r;Mt.mark("constructor")}vfs;autoSudoForNewUsers;static recordCache=new Map;static fastPasswordHash=Uy();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(){Mt.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");let r="/root";this.vfs.exists(r)||(this.vfs.mkdir(r,493),this.vfs.writeFile(`${r}/README.txt`,"Welcome to the virtual environment, root")),e&&await this.persist(),this.emit("initialized")}async setQuotaBytes(e,r){if(Mt.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){Mt.mark("clearQuota"),this.validateUsername(e),this.quotas.delete(e),await this.persist()}getQuotaBytes(e){return Mt.mark("getQuotaBytes"),this.quotas.get(e)??null}getUsageBytes(e){Mt.mark("getUsageBytes");let r=e==="root"?"/root":`/home/${e}`;return this.vfs.exists(r)?this.vfs.getUsageBytes(r):0}assertWriteWithinQuota(e,r,s){Mt.mark("assertWriteWithinQuota");let i=this.quotas.get(e);if(i===void 0)return;let o=Dh(r),a=Dh(e==="root"?"/root":`/home/${e}`);if(!(o===a||o.startsWith(`${a}/`)))return;let l=this.getUsageBytes(e),u=0;if(this.vfs.exists(o)){let p=this.vfs.stat(o);p.type==="file"&&(u=p.size)}let f=Buffer.isBuffer(s)?s.length:Buffer.byteLength(s,"utf8"),h=l-u+f;if(h>i)throw new Error(`quota exceeded for '${e}': ${h}/${i} bytes`)}verifyPassword(e,r){Mt.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,In.timingSafeEqual)(a,c)}catch{return i===o}}async addUser(e,r){if(Mt.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=e==="root"?"/root":`/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){Mt.mark("getPasswordHash");let r=this.users.get(e);return r?r.passwordHash:null}async setPassword(e,r){if(Mt.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(Mt.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 Mt.mark("isSudoer"),this.sudoers.has(e)}async addSudoer(e){if(Mt.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(Mt.mark("removeSudoer"),this.validateUsername(e),e==="root")throw new Error("sudoers: cannot remove root");this.sudoers.delete(e),await this.persist()}registerSession(e,r){Mt.mark("registerSession");let s={id:(0,In.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(Mt.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(Mt.mark("updateSession"),!e)return;let i=this.activeSessions.get(e);i&&this.activeSessions.set(e,{...i,username:r,remoteAddress:s})}listActiveSessions(){return Mt.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(`
1720
- `)){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(`
1721
- `)){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(`
1722
- `)){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(`
1708
+ `)){let i=r.indexOf(": ");i!==-1&&(e[r.slice(0,i)]=r.slice(i+2))}return e}log(t){let r=`${new Date().toISOString().replace("T"," ").slice(0,19)} ${t}
1709
+ `,i=this.vfs.exists(this.logPath)?this.vfs.readFile(this.logPath):"";this.vfs.writeFile(this.logPath,i+r)}aptLog(t,e){let r=new Date().toISOString(),i=this.vfs.exists(this.aptLogPath)?this.vfs.readFile(this.aptLogPath):"",s=[`Start-Date: ${r}`,`Commandline: apt-get ${t} ${e.join(" ")}`,`${t==="install"?"Install":"Remove"}: ${e.join(", ")}`,`End-Date: ${r}`,""].join(`
1710
+ `);this.vfs.writeFile(this.aptLogPath,i+s)}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=[],i=[],s=[],o=(c,l=new Set)=>{if(l.has(c)||(l.add(c),this.isInstalled(c)))return;let u=this.findInRegistry(c);if(!u){s.push(c);return}for(let f of u.depends??[])o(f,l);i.find(f=>f.name===u.name)||i.push(u)};for(let c of t)o(c);if(s.length>0)return{output:`E: Unable to locate package ${s.join(", ")}`,exitCode:100};if(i.length===0)return{output:t.map(c=>`${c} is already the newest version.`).join(`
1711
+ `),exitCode:0};let a=i.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:",` ${i.map(c=>c.name).join(" ")}`,`0 upgraded, ${i.length} newly installed, 0 to remove and 0 not upgraded.`,`Need to get 0 B/${a} kB of archives.`,`After this operation, ${a} kB of additional disk space will be used.`,"");for(let c of i){e.quiet||(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 u of c.files??[]){let f=u.path.slice(0,u.path.lastIndexOf("/"));f&&!this.vfs.exists(f)&&this.vfs.mkdir(f,493),this.vfs.writeFile(u.path,u.content,{mode:u.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(u=>u.path)}),this.log(`install ${c.name} ${c.version}`)}return this.aptLog("install",i.map(c=>c.name)),this.persist(),e.quiet||r.push("Processing triggers for man-db (2.11.2-2) ..."),{output:r.join(`
1712
+ `),exitCode:0}}remove(t,e={}){let r=[],i=[];for(let s of t){let o=this.installed.get(s.toLowerCase());o?i.push(o):r.push(`Package '${s}' is not installed, so not removed`)}if(i.length===0)return{output:r.join(`
1713
+ `)||"Nothing to remove.",exitCode:0};e.quiet||r.push("Reading package lists... Done","Building dependency tree... Done","The following packages will be REMOVED:",` ${i.map(s=>s.name).join(" ")}`,`0 upgraded, 0 newly installed, ${i.length} to remove and 0 not upgraded.`);for(let s of i){e.quiet||r.push(`Removing ${s.name} (${s.version}) ...`);for(let a of s.files)if(!(!e.purge&&(a.startsWith("/etc/")||a.endsWith(".conf"))))try{this.vfs.exists(a)&&this.vfs.remove(a)}catch{}this.findInRegistry(s.name)?.onRemove?.(this.vfs),this.installed.delete(s.name),this.log(`remove ${s.name} ${s.version}`)}return this.aptLog("remove",i.map(s=>s.name)),this.persist(),{output:r.join(`
1714
+ `),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,i)=>r.name.localeCompare(i.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(`
1715
+ `)}};var In=require("node:crypto"),Fh=require("node:events"),Hh=Yt(require("node:path"),1);function Hy(){let n=process.env.SSH_MIMIC_FAST_PASSWORD_HASH;return!!n&&!["0","false","no","off"].includes(n.toLowerCase())}var Mt=cr("VirtualUserManager"),lo=class n extends Fh.EventEmitter{constructor(e,r=!0){super();this.vfs=e;this.autoSudoForNewUsers=r;Mt.mark("constructor")}vfs;autoSudoForNewUsers;static recordCache=new Map;static fastPasswordHash=Hy();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(){Mt.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");let r="/root";this.vfs.exists(r)||(this.vfs.mkdir(r,493),this.vfs.writeFile(`${r}/README.txt`,"Welcome to the virtual environment, root")),e&&await this.persist(),this.emit("initialized")}async setQuotaBytes(e,r){if(Mt.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){Mt.mark("clearQuota"),this.validateUsername(e),this.quotas.delete(e),await this.persist()}getQuotaBytes(e){return Mt.mark("getQuotaBytes"),this.quotas.get(e)??null}getUsageBytes(e){Mt.mark("getUsageBytes");let r=e==="root"?"/root":`/home/${e}`;return this.vfs.exists(r)?this.vfs.getUsageBytes(r):0}assertWriteWithinQuota(e,r,i){Mt.mark("assertWriteWithinQuota");let s=this.quotas.get(e);if(s===void 0)return;let o=$h(r),a=$h(e==="root"?"/root":`/home/${e}`);if(!(o===a||o.startsWith(`${a}/`)))return;let l=this.getUsageBytes(e),u=0;if(this.vfs.exists(o)){let p=this.vfs.stat(o);p.type==="file"&&(u=p.size)}let f=Buffer.isBuffer(i)?i.length:Buffer.byteLength(i,"utf8"),h=l-u+f;if(h>s)throw new Error(`quota exceeded for '${e}': ${h}/${s} bytes`)}verifyPassword(e,r){Mt.mark("verifyPassword");let i=this.users.get(e);if(!i)return this.hashPassword(r,""),!1;let s=this.hashPassword(r,i.salt),o=i.passwordHash;try{let a=Buffer.from(s,"hex"),c=Buffer.from(o,"hex");return a.length!==c.length?!1:(0,In.timingSafeEqual)(a,c)}catch{return s===o}}async addUser(e,r){if(Mt.mark("addUser"),this.validateUsername(e),this.validatePassword(r),this.users.has(e))return;this.users.set(e,this.createRecord(e,r)),this.autoSudoForNewUsers&&this.sudoers.add(e);let i=e==="root"?"/root":`/home/${e}`;this.vfs.exists(i)||(this.vfs.mkdir(i,493),this.vfs.writeFile(`${i}/README.txt`,`Welcome to the virtual environment, ${e}`)),await this.persist(),this.emit("user:add",{username:e})}getPasswordHash(e){Mt.mark("getPasswordHash");let r=this.users.get(e);return r?r.passwordHash:null}async setPassword(e,r){if(Mt.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(Mt.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 Mt.mark("isSudoer"),this.sudoers.has(e)}async addSudoer(e){if(Mt.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(Mt.mark("removeSudoer"),this.validateUsername(e),e==="root")throw new Error("sudoers: cannot remove root");this.sudoers.delete(e),await this.persist()}registerSession(e,r){Mt.mark("registerSession");let i={id:(0,In.randomUUID)(),username:e,tty:`pts/${this.nextTty++}`,remoteAddress:r,startedAt:new Date().toISOString()};return this.activeSessions.set(i.id,i),this.emit("session:register",{sessionId:i.id,username:e,remoteAddress:r}),i}unregisterSession(e){if(Mt.mark("unregisterSession"),!e)return;let r=this.activeSessions.get(e);this.activeSessions.delete(e),r&&this.emit("session:unregister",{sessionId:e,username:r.username}),this.activeSessions.delete(e)}updateSession(e,r,i){if(Mt.mark("updateSession"),!e)return;let s=this.activeSessions.get(e);s&&this.activeSessions.set(e,{...s,username:r,remoteAddress:i})}listActiveSessions(){return Mt.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(`
1716
+ `)){let i=r.trim();if(i.length===0)continue;let s=i.split(":");if(s.length<3)continue;let[o,a,c]=s;!o||!a||!c||this.users.set(o,{username:o,salt:a,passwordHash:c})}}loadSudoersFromVfs(){if(this.sudoers.clear(),!this.vfs.exists(this.sudoersPath))return;let e=this.vfs.readFile(this.sudoersPath);for(let r of e.split(`
1717
+ `)){let i=r.trim();i.length>0&&this.sudoers.add(i)}}loadQuotasFromVfs(){if(this.quotas.clear(),!this.vfs.exists(this.quotasPath))return;let e=this.vfs.readFile(this.quotasPath);for(let r of e.split(`
1718
+ `)){let i=r.trim();if(i.length===0)continue;let[s,o]=i.split(":"),a=Number.parseInt(o??"",10);!s||!Number.isFinite(a)||a<0||this.quotas.set(s,a)}}async persist(){this.vfs.exists(this.authDirPath)||this.vfs.mkdir(this.authDirPath,448);let e=Array.from(this.users.values()).sort((o,a)=>o.username.localeCompare(a.username)).map(o=>[o.username,o.salt,o.passwordHash].join(":")).join(`
1723
1719
  `),r=Array.from(this.sudoers.values()).sort().join(`
1724
- `),s=Array.from(this.quotas.entries()).sort(([o],[a])=>o.localeCompare(a)).map(([o,a])=>`${o}:${a}`).join(`
1725
- `),i=!1;i=this.writeIfChanged(this.usersPath,e.length>0?`${e}
1726
- `:"",384)||i,i=this.writeIfChanged(this.sudoersPath,r.length>0?`${r}
1727
- `:"",384)||i,i=this.writeIfChanged(this.quotasPath,s.length>0?`${s}
1728
- `:"",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,In.createHash)("sha256").update(e).update(":").update(r).digest("hex"),i=n.recordCache.get(s);if(i)return i;let o=(0,In.randomBytes)(16).toString("hex"),a={username:e,salt:o,passwordHash:this.hashPassword(r,o)};return n.recordCache.set(s,a),a}hasPassword(e){Mt.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,In.createHash)("sha256").update(r).update(e).digest("hex"):(0,In.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){Mt.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 Dh(n){let t=$h.posix.normalize(n);return t.startsWith("/")?t:`/${t}`}var Fh=require("node:events");var co=class extends Fh.EventEmitter{vfs;idleThresholdMs;checkIntervalMs;_state="active";_lastActivity=Date.now();_frozenBuffer=null;_checkTimer=null;constructor(t,e={}){super(),this.vfs=t,this.idleThresholdMs=e.idleThresholdMs??6e4,this.checkIntervalMs=e.checkIntervalMs??15e3}start(){this._checkTimer||(this._lastActivity=Date.now(),this._checkTimer=setInterval(()=>this._check(),this.checkIntervalMs),typeof this._checkTimer=="object"&&this._checkTimer!==null&&"unref"in this._checkTimer&&this._checkTimer.unref())}async stop(){this._checkTimer&&(clearInterval(this._checkTimer),this._checkTimer=null),this._state==="frozen"&&this._thaw()}ping(){this._lastActivity=Date.now(),this._state==="frozen"&&this._thaw()}get state(){return this._state}get idleMs(){return Date.now()-this._lastActivity}_check(){this._state!=="frozen"&&Date.now()-this._lastActivity>=this.idleThresholdMs&&this._freeze()}async _freeze(){this._state!=="frozen"&&(await this.vfs.stopAutoFlush(),this._frozenBuffer=this.vfs.encodeBinary(),this.vfs.releaseTree(),this._state="frozen",this.emit("freeze"))}_thaw(){if(this._state!=="frozen"||!this._frozenBuffer)return;let t=or(this._frozenBuffer);this.vfs.importRootTree(t),this._frozenBuffer=null,this._state="active",this.emit("thaw")}};var ni=require("node:fs/promises"),Bc=Yt(require("node:path"),1);var Vh=require("node:child_process");var Hh=require("node:fs/promises"),lo=Yt(require("node:path"),1);function Nc(n){return`'${n.replace(/'/g,"'\\''")}'`}function Ki(n){return n.replace(/\r\n/g,`
1720
+ `),i=Array.from(this.quotas.entries()).sort(([o],[a])=>o.localeCompare(a)).map(([o,a])=>`${o}:${a}`).join(`
1721
+ `),s=!1;s=this.writeIfChanged(this.usersPath,e.length>0?`${e}
1722
+ `:"",384)||s,s=this.writeIfChanged(this.sudoersPath,r.length>0?`${r}
1723
+ `:"",384)||s,s=this.writeIfChanged(this.quotasPath,i.length>0?`${i}
1724
+ `:"",384)||s,s&&await this.vfs.flushMirror()}writeIfChanged(e,r,i){return this.vfs.exists(e)&&this.vfs.readFile(e)===r?(this.vfs.chmod(e,i),!1):(this.vfs.writeFile(e,r,{mode:i}),!0)}createRecord(e,r){let i=(0,In.createHash)("sha256").update(e).update(":").update(r).digest("hex"),s=n.recordCache.get(i);if(s)return s;let o=(0,In.randomBytes)(16).toString("hex"),a={username:e,salt:o,passwordHash:this.hashPassword(r,o)};return n.recordCache.set(i,a),a}hasPassword(e){Mt.mark("hasPassword");let r=this.users.get(e);if(!r)return!1;let i=this.hashPassword("",r.salt);return r.passwordHash===i?!1:!!r.passwordHash}hashPassword(e,r=""){return n.fastPasswordHash?(0,In.createHash)("sha256").update(r).update(e).digest("hex"):(0,In.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,i){Mt.mark("addAuthorizedKey");let s=this.authorizedKeys.get(e)??[];s.push({algo:r,data:i}),this.authorizedKeys.set(e,s),this.emit("key:add",{username:e,algo:r})}removeAuthorizedKeys(e){this.authorizedKeys.delete(e),this.emit("key:remove",{username:e})}getAuthorizedKeys(e){return this.authorizedKeys.get(e)??[]}};function $h(n){let t=Hh.posix.normalize(n);return t.startsWith("/")?t:`/${t}`}var Qh=require("node:events");var uo=class extends Qh.EventEmitter{vfs;idleThresholdMs;checkIntervalMs;_state="active";_lastActivity=Date.now();_frozenBuffer=null;_checkTimer=null;constructor(t,e={}){super(),this.vfs=t,this.idleThresholdMs=e.idleThresholdMs??6e4,this.checkIntervalMs=e.checkIntervalMs??15e3}start(){this._checkTimer||(this._lastActivity=Date.now(),this._checkTimer=setInterval(()=>this._check(),this.checkIntervalMs),typeof this._checkTimer=="object"&&this._checkTimer!==null&&"unref"in this._checkTimer&&this._checkTimer.unref())}async stop(){this._checkTimer&&(clearInterval(this._checkTimer),this._checkTimer=null),this._state==="frozen"&&this._thaw()}ping(){this._lastActivity=Date.now(),this._state==="frozen"&&this._thaw()}get state(){return this._state}get idleMs(){return Date.now()-this._lastActivity}_check(){this._state!=="frozen"&&Date.now()-this._lastActivity>=this.idleThresholdMs&&this._freeze()}async _freeze(){this._state!=="frozen"&&(await this.vfs.stopAutoFlush(),this._frozenBuffer=this.vfs.encodeBinary(),this.vfs.releaseTree(),this._state="frozen",this.emit("freeze"))}_thaw(){if(this._state!=="frozen"||!this._frozenBuffer)return;let t=ar(this._frozenBuffer);this.vfs.importRootTree(t),this._frozenBuffer=null,this._state="active",this.emit("thaw")}};var ri=require("node:fs/promises"),Pc=Yt(require("node:path"),1);var Gh=require("node:child_process");var Wh=require("node:fs/promises"),fo=Yt(require("node:path"),1);function Rc(n){return`'${n.replace(/'/g,"'\\''")}'`}function Vi(n){return n.replace(/\r\n/g,`
1729
1725
  `).replace(/\r/g,`
1730
1726
  `).replace(/\n/g,`\r
1731
- `)}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("/")?lo.posix.normalize(t):lo.posix.normalize(lo.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 -- ${Nc(n)}`,t,e)}function Yh(n,t,e){return zh(`htop -p ${Nc(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:to(s);r.push(`Last login: ${i} from ${e.from||"unknown"}`)}return r.push(""),`${r.map(s=>`${s}\r
1732
- `).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,u=$y(a.vfs,e),f=null,h="",p=Pt(e),y=jr(e,r),E=null,S=null,x=()=>{let B=Pt(e),L=p===B?"~":Bc.posix.basename(p)||"/";return Xh(e,r,L)},P=Array.from(new Set(cc())).sort();console.log(`[${s}] Shell started for user '${e}' at ${i}`),(async()=>{let B=`${Pt(e)}/.bashrc`;if(a.vfs.exists(B))try{let L=a.vfs.readFile(B);for(let z of L.split(`
1727
+ `)}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 Kh(n,t){return!t||t.trim()===""||t==="."?n:t.startsWith("/")?fo.posix.normalize(t):fo.posix.normalize(fo.posix.join(n,t))}async function Vh(n){try{let e=(await(0,Wh.readFile)(`/proc/${n}/task/${n}/children`,"utf8")).trim().split(/\s+/).filter(Boolean).map(i=>Number.parseInt(i,10)).filter(i=>Number.isInteger(i)&&i>0),r=await Promise.all(e.map(i=>Vh(i)));return[...e,...r.flat()]}catch{return[]}}async function zh(n=process.pid){let t=await Vh(n),e=Array.from(new Set(t)).sort((r,i)=>r-i);return e.length===0?null:e.join(",")}function Yh(n,t,e){let r=qh(n,t),i=(0,Gh.spawn)("script",["-qfec",r,"/dev/null"],{stdio:["pipe","pipe","pipe"],env:{...process.env,TERM:process.env.TERM??"xterm-256color"}});return i.stdout.on("data",s=>{e.write(s.toString("utf8"))}),i.stderr.on("data",s=>{e.write(s.toString("utf8"))}),i}function jh(n,t,e){return Yh(`nano -- ${Rc(n)}`,t,e)}function Xh(n,t,e){return Yh(`htop -p ${Rc(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 i=new Date(e.at),s=Number.isNaN(i.getTime())?e.at:ro(i);r.push(`Last login: ${s} from ${e.from||"unknown"}`)}return r.push(""),`${r.map(i=>`${i}\r
1728
+ `).join("")}`}function Zh(n,t,e){let r=n==="root",i=r?"\x1B[31;1m":"\x1B[35;1m",s="\x1B[37;1m",o="\x1B[34;1m",a="\x1B[0m";return`${s}[${i}${n}${s}@${o}${t}${a} ${e}${s}]${a}${r?"#":"$"} `}function ep(n,t,e,r,i,s="unknown",o={cols:80,rows:24},a){let c="",l=0,u=Qy(a.vfs,e),f=null,h="",p=Pt(e),y=Xr(e,r),E=null,S=null,x=()=>{let B=Pt(e),L=p===B?"~":Pc.posix.basename(p)||"/";return Zh(e,r,L)},P=Array.from(new Set(uc())).sort();console.log(`[${i}] Shell started for user '${e}' at ${s}`),(async()=>{let B=`${Pt(e)}/.bashrc`;if(a.vfs.exists(B))try{let L=a.vfs.readFile(B);for(let z of L.split(`
1733
1729
  `)){let ne=z.trim();!ne||ne.startsWith("#")||await wt(ne,e,r,"shell",p,a,void 0,y)}}catch{}})();function q(){let B=x();t.write(`\r${B}${c}\x1B[K`);let L=c.length-l;L>0&&t.write(`\x1B[${L}D`)}function C(){t.write("\r\x1B[K")}function $(B){S={...B,buffer:""},C(),t.write(B.prompt)}async function F(B){if(!S)return;let L=S;if(S=null,!B){t.write(`\r
1734
1730
  Sorry, try again.\r
1735
- `),q();return}if(!L.commandLine){e=L.targetUser,L.loginShell&&(p=Pt(e)),a.users.updateSession(s,e,i),t.write(`\r
1731
+ `),q();return}if(!L.commandLine){e=L.targetUser,L.loginShell&&(p=Pt(e)),a.users.updateSession(i,e,s),t.write(`\r
1736
1732
  `),q();return}let z=L.loginShell?Pt(L.targetUser):p,ne=await Promise.resolve(wt(L.commandLine,L.targetUser,r,"shell",z,a));if(t.write(`\r
1737
- `),ne.openEditor){await b(ne.openEditor.targetPath,ne.openEditor.initialContent,ne.openEditor.tempPath);return}if(ne.openHtop){await w();return}ne.clearScreen&&t.write("\x1B[2J\x1B[H"),ne.stdout&&t.write(`${Ki(ne.stdout)}\r
1738
- `),ne.stderr&&t.write(`${Ki(ne.stderr)}\r
1739
- `),ne.switchUser?(e=ne.switchUser,p=ne.nextCwd??Pt(e),a.users.updateSession(s,e,i)):ne.nextCwd&&(p=ne.nextCwd),q()}async function v(){if(!E)return;let B=E;if(B.kind==="nano"){try{let L=await(0,ni.readFile)(B.tempPath,"utf8");a.writeFileAsUser(e,B.targetPath,L)}catch{}await(0,ni.unlink)(B.tempPath).catch(()=>{})}E=null,c="",l=0,t.write(`\r
1740
- `),q()}async function b(B,L,z){a.vfs.exists(B)&&await(0,ni.writeFile)(z,L,"utf8");let ne=Gh(z,o,t);ne.on("error",de=>{t.write(`nano: ${de.message}\r
1741
- `),v()}),ne.on("close",()=>{v()}),E={kind:"nano",targetPath:B,tempPath:z,process:ne}}async function w(){let B=await Kh();if(!B){t.write(`htop: no child_process processes to display\r
1742
- `);return}let L=Yh(B,o,t);L.on("error",z=>{t.write(`htop: ${z.message}\r
1743
- `),v()}),L.on("close",()=>{v()}),E={kind:"htop",targetPath:"",tempPath:"",process:L}}function k(B){c=B,l=c.length,q()}function N(B){c=`${c.slice(0,l)}${B}${c.slice(l)}`,l+=B.length,q()}function R(B,L){let z=L;for(;z>0&&!/\s/.test(B[z-1]);)z-=1;let ne=L;for(;ne<B.length&&!/\s/.test(B[ne]);)ne+=1;return{start:z,end:ne}}function ie(B){let L=B.lastIndexOf("/"),z=L>=0?B.slice(0,L+1):"",ne=L>=0?B.slice(L+1):B,de=Wh(p,z||".");try{return a.vfs.list(de).filter(oe=>!oe.startsWith(".")).filter(oe=>oe.startsWith(ne)).map(oe=>{let Xe=Bc.posix.join(de,oe),cn=a.vfs.stat(Xe).type==="directory"?"/":"";return`${z}${oe}${cn}`}).sort()}catch{return[]}}function j(){let{start:B,end:L}=R(c,l),z=c.slice(B,l);if(z.length===0)return;let de=c.slice(0,B).trim().length===0?P.filter(dt=>dt.startsWith(z)):[],oe=ie(z),Xe=Array.from(new Set([...de,...oe])).sort();if(Xe.length!==0){if(Xe.length===1){let dt=Xe[0],cn=dt.endsWith("/")?"":" ";c=`${c.slice(0,B)}${dt}${cn}${c.slice(L)}`,l=B+dt.length+cn.length,q();return}t.write(`\r
1733
+ `),ne.openEditor){await b(ne.openEditor.targetPath,ne.openEditor.initialContent,ne.openEditor.tempPath);return}if(ne.openHtop){await w();return}ne.clearScreen&&t.write("\x1B[2J\x1B[H"),ne.stdout&&t.write(`${Vi(ne.stdout)}\r
1734
+ `),ne.stderr&&t.write(`${Vi(ne.stderr)}\r
1735
+ `),ne.switchUser?(e=ne.switchUser,p=ne.nextCwd??Pt(e),a.users.updateSession(i,e,s)):ne.nextCwd&&(p=ne.nextCwd),q()}async function v(){if(!E)return;let B=E;if(B.kind==="nano"){try{let L=await(0,ri.readFile)(B.tempPath,"utf8");a.writeFileAsUser(e,B.targetPath,L)}catch{}await(0,ri.unlink)(B.tempPath).catch(()=>{})}E=null,c="",l=0,t.write(`\r
1736
+ `),q()}async function b(B,L,z){a.vfs.exists(B)&&await(0,ri.writeFile)(z,L,"utf8");let ne=jh(z,o,t);ne.on("error",de=>{t.write(`nano: ${de.message}\r
1737
+ `),v()}),ne.on("close",()=>{v()}),E={kind:"nano",targetPath:B,tempPath:z,process:ne}}async function w(){let B=await zh();if(!B){t.write(`htop: no child_process processes to display\r
1738
+ `);return}let L=Xh(B,o,t);L.on("error",z=>{t.write(`htop: ${z.message}\r
1739
+ `),v()}),L.on("close",()=>{v()}),E={kind:"htop",targetPath:"",tempPath:"",process:L}}function k(B){c=B,l=c.length,q()}function N(B){c=`${c.slice(0,l)}${B}${c.slice(l)}`,l+=B.length,q()}function R(B,L){let z=L;for(;z>0&&!/\s/.test(B[z-1]);)z-=1;let ne=L;for(;ne<B.length&&!/\s/.test(B[ne]);)ne+=1;return{start:z,end:ne}}function ie(B){let L=B.lastIndexOf("/"),z=L>=0?B.slice(0,L+1):"",ne=L>=0?B.slice(L+1):B,de=Kh(p,z||".");try{return a.vfs.list(de).filter(oe=>!oe.startsWith(".")).filter(oe=>oe.startsWith(ne)).map(oe=>{let Xe=Pc.posix.join(de,oe),cn=a.vfs.stat(Xe).type==="directory"?"/":"";return`${z}${oe}${cn}`}).sort()}catch{return[]}}function j(){let{start:B,end:L}=R(c,l),z=c.slice(B,l);if(z.length===0)return;let de=c.slice(0,B).trim().length===0?P.filter(dt=>dt.startsWith(z)):[],oe=ie(z),Xe=Array.from(new Set([...de,...oe])).sort();if(Xe.length!==0){if(Xe.length===1){let dt=Xe[0],cn=dt.endsWith("/")?"":" ";c=`${c.slice(0,B)}${dt}${cn}${c.slice(L)}`,l=B+dt.length+cn.length,q();return}t.write(`\r
1744
1740
  `),t.write(`${Xe.join(" ")}\r
1745
1741
  `),q()}}function X(B){if(B.length===0)return;u.push(B),u.length>500&&(u=u.slice(u.length-500));let L=u.length>0?`${u.join(`
1746
1742
  `)}
1747
- `:"";a.vfs.writeFile(`${Pt(e)}/.bash_history`,L)}function re(){let B=`${Pt(e)}/.lastlog.json`;if(!a.vfs.exists(B))return null;try{return JSON.parse(a.vfs.readFile(B))}catch{return null}}function fe(B){let L=`${Pt(e)}/.lastlog`;a.vfs.writeFile(L,JSON.stringify({at:B,from:i}))}function H(){let B=re(),L=new Date().toISOString();t.write(jh(r,n,B)),fe(L)}H(),q(),t.on("data",async B=>{if(E){E.process.stdin.write(B);return}if(S){let z=B.toString("utf8");for(let ne=0;ne<z.length;ne+=1){let de=z[ne];if(de===""){S=null,t.write(`^C\r
1743
+ `:"";a.vfs.writeFile(`${Pt(e)}/.bash_history`,L)}function re(){let B=`${Pt(e)}/.lastlog.json`;if(!a.vfs.exists(B))return null;try{return JSON.parse(a.vfs.readFile(B))}catch{return null}}function fe(B){let L=`${Pt(e)}/.lastlog`;a.vfs.writeFile(L,JSON.stringify({at:B,from:s}))}function H(){let B=re(),L=new Date().toISOString();t.write(Jh(r,n,B)),fe(L)}H(),q(),t.on("data",async B=>{if(E){E.process.stdin.write(B);return}if(S){let z=B.toString("utf8");for(let ne=0;ne<z.length;ne+=1){let de=z[ne];if(de===""){S=null,t.write(`^C\r
1748
1744
  `),q();return}if(de==="\x7F"||de==="\b"){S.buffer=S.buffer.slice(0,-1);continue}if(de==="\r"||de===`
1749
1745
  `){let oe=S.buffer;if(S.buffer="",S.onPassword){let{result:dt,nextPrompt:cn}=await S.onPassword(oe,a);t.write(`\r
1750
1746
  `),dt!==null?(S=null,dt.stdout&&t.write(dt.stdout.replace(/\n/g,`\r
@@ -1754,15 +1750,15 @@ Sorry, try again.\r
1754
1750
  `),t.exit(0),t.end();return}if(ne===" "){j();continue}if(ne==="\x1B"){let de=L[z+1],oe=L[z+2],Xe=L[z+3];if(de==="["&&oe){if(oe==="A"){z+=2,u.length>0&&(f===null?(h=c,f=u.length-1):f>0&&(f-=1),k(u[f]??""));continue}if(oe==="B"){z+=2,f!==null&&(f<u.length-1?(f+=1,k(u[f]??"")):(f=null,k(h)));continue}if(oe==="C"){z+=2,l<c.length&&(l+=1,t.write("\x1B[C"));continue}if(oe==="D"){z+=2,l>0&&(l-=1,t.write("\x1B[D"));continue}if(oe==="3"&&Xe==="~"){z+=3,l<c.length&&(c=`${c.slice(0,l)}${c.slice(l+1)}`,q());continue}}}if(ne===""){c="",l=0,f=null,h="",t.write(`^C\r
1755
1751
  `),q();continue}if(ne==="\r"||ne===`
1756
1752
  `){let de=c.trim();if(c="",l=0,f=null,h="",t.write(`\r
1757
- `),de.length>0){let oe=await Promise.resolve(wt(de,e,r,"shell",p,a,void 0,y));if(X(de),oe.openEditor){await b(oe.openEditor.targetPath,oe.openEditor.initialContent,oe.openEditor.tempPath);return}if(oe.openHtop){await w();return}if(oe.sudoChallenge){$(oe.sudoChallenge);return}if(oe.clearScreen&&t.write("\x1B[2J\x1B[H"),oe.stdout&&t.write(`${Ki(oe.stdout)}\r
1758
- `),oe.stderr&&t.write(`${Ki(oe.stderr)}\r
1753
+ `),de.length>0){let oe=await Promise.resolve(wt(de,e,r,"shell",p,a,void 0,y));if(X(de),oe.openEditor){await b(oe.openEditor.targetPath,oe.openEditor.initialContent,oe.openEditor.tempPath);return}if(oe.openHtop){await w();return}if(oe.sudoChallenge){$(oe.sudoChallenge);return}if(oe.clearScreen&&t.write("\x1B[2J\x1B[H"),oe.stdout&&t.write(`${Vi(oe.stdout)}\r
1754
+ `),oe.stderr&&t.write(`${Vi(oe.stderr)}\r
1759
1755
  `),oe.closeSession){t.write(`logout\r
1760
- `),t.exit(oe.exitCode??0),t.end();return}oe.nextCwd&&(p=oe.nextCwd),oe.switchUser&&(e=oe.switchUser,p=oe.nextCwd??Pt(e),a.users.updateSession(s,e,i),c="",l=0)}q();continue}if(ne==="\x7F"||ne==="\b"){l>0&&(c=`${c.slice(0,l-1)}${c.slice(l)}`,l-=1,q());continue}N(ne)}}),t.on("close",()=>{E&&(E.process.kill("SIGTERM"),E=null)})}function $y(n,t){let e=`${Pt(t)}/.bash_history`;return n.exists(e)?n.readFile(e).split(`
1761
- `).map(s=>s.trim()).filter(s=>s.length>0):(n.writeFile(e,""),[])}function Fy(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 Hy={kernel:"1.0.0+itsrealfortune+1-amd64",os:"Fortune GNU/Linux x64",arch:"x86_64"},Vi=ar("VirtualShell");function Qy(){let n=process.env.SSH_MIMIC_AUTO_SUDO_NEW_USERS;return n?!["0","false","no","off"].includes(n.toLowerCase()):!0}var _r=class extends Zh.EventEmitter{vfs;users;packageManager;hostname;properties;startTime;_idle=null;initialized;constructor(t,e,r){super(),Vi.mark("constructor"),this.hostname=t,this.properties=e||Hy,this.startTime=Date.now(),ep(r)?this.vfs=r:Fy(r)?this.vfs=r.vfsInstance:this.vfs=new io(r??{}),this.users=new ao(this.vfs,Qy()),this.packageManager=new oo(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(),Oh(s,i,c,a,l),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");oc(ac(s,e,r))}executeCommand(t,e,r){Vi.mark("executeCommand"),this._idle?.ping(),wt(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._idle?.ping(),this.emit("session:start",{user:e,sessionId:r,remoteAddress:s}),Jh(this.properties,t,e,this.hostname,r,s,i,this),this.refreshProcSessions()}refreshProcFs(){so(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(){so(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}syncPasswd(){kc(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)}enableIdleManagement(t){this._idle||(this._idle=new co(this.vfs,t),this._idle.on("freeze",()=>this.emit("shell:freeze")),this._idle.on("thaw",()=>this.emit("shell:thaw")),this._idle.start())}async disableIdleManagement(){this._idle&&(await this._idle.stop(),this._idle=null)}get idleState(){return this._idle?.state??"active"}get idleMs(){return this._idle?.idleMs??0}pingIdle(){this._idle?.ping()}};function tp(n){return n.replace(/\r\n/g,`
1756
+ `),t.exit(oe.exitCode??0),t.end();return}oe.nextCwd&&(p=oe.nextCwd),oe.switchUser&&(e=oe.switchUser,p=oe.nextCwd??Pt(e),a.users.updateSession(i,e,s),c="",l=0)}q();continue}if(ne==="\x7F"||ne==="\b"){l>0&&(c=`${c.slice(0,l-1)}${c.slice(l)}`,l-=1,q());continue}N(ne)}}),t.on("close",()=>{E&&(E.process.kill("SIGTERM"),E=null)})}function Qy(n,t){let e=`${Pt(t)}/.bash_history`;return n.exists(e)?n.readFile(e).split(`
1757
+ `).map(i=>i.trim()).filter(i=>i.length>0):(n.writeFile(e,""),[])}function Wy(n){return typeof n=="object"&&n!==null&&"vfsInstance"in n&&np(n.vfsInstance)}function np(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 qy={kernel:"1.0.0+itsrealfortune+1-amd64",os:"Fortune GNU/Linux x64",arch:"x86_64"},zi=cr("VirtualShell");function Ky(){let n=process.env.SSH_MIMIC_AUTO_SUDO_NEW_USERS;return n?!["0","false","no","off"].includes(n.toLowerCase()):!0}var br=class extends tp.EventEmitter{vfs;users;packageManager;hostname;properties;startTime;_idle=null;initialized;constructor(t,e,r){super(),zi.mark("constructor"),this.hostname=t,this.properties=e||qy,this.startTime=Date.now(),np(r)?this.vfs=r:Wy(r)?this.vfs=r.vfsInstance:this.vfs=new oo(r??{}),this.users=new lo(this.vfs,Ky()),this.packageManager=new co(this.vfs,this.users);let i=this.vfs,s=this.users,o=this.packageManager,a=this.properties,c=this.hostname,l=this.startTime;this.initialized=(async()=>{await i.restoreMirror(),await s.initialize(),Lh(i,s,c,a,l),o.load(),this.emit("initialized")})()}async ensureInitialized(){zi.mark("ensureInitialized"),await this.initialized}addCommand(t,e,r){let i=t.trim().toLowerCase();if(i.length===0||/\s/.test(i))throw new Error("Command name must be non-empty and contain no spaces");cc(lc(i,e,r))}executeCommand(t,e,r){zi.mark("executeCommand"),this._idle?.ping();let i=wt(t,e,this.hostname,"shell",r,this);return this.emit("command",{command:t,user:e,cwd:r}),i}startInteractiveSession(t,e,r,i,s){zi.mark("startInteractiveSession"),this._idle?.ping(),this.emit("session:start",{user:e,sessionId:r,remoteAddress:i}),ep(this.properties,t,e,this.hostname,r,i,s,this),this.refreshProcSessions()}refreshProcFs(){ao(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(){ao(this.vfs,this.properties,this.hostname,this.startTime,this.users.listActiveSessions())}syncPasswd(){Nc(this.vfs,this.users)}getVfs(){return this?.vfs??null}getUsers(){return this?.users??null}getHostname(){return this?.hostname}writeFileAsUser(t,e,r){zi.mark("writeFileAsUser"),this.users.assertWriteWithinQuota(t,e,r),this.vfs.writeFile(e,r)}enableIdleManagement(t){this._idle||(this._idle=new uo(this.vfs,t),this._idle.on("freeze",()=>this.emit("shell:freeze")),this._idle.on("thaw",()=>this.emit("shell:thaw")),this._idle.start())}async disableIdleManagement(){this._idle&&(await this._idle.stop(),this._idle=null)}get idleState(){return this._idle?.state??"active"}get idleMs(){return this._idle?.idleMs??0}pingIdle(){this._idle?.ping()}};function rp(n){return n.replace(/\r\n/g,`
1762
1758
  `).replace(/\r/g,`
1763
1759
  `).replace(/\n/g,`\r
1764
- `)}function np(n,t,e,r,s){Promise.resolve(wt(t,e,r,"exec",Pt(e),s,void 0,jr(e,r))).then(i=>{i.stdout&&n.write(`${tp(i.stdout)}\r
1765
- `),i.stderr&&n.stderr.write(`${tp(i.stderr)}\r
1766
- `),n.exit(i.exitCode??0),n.end()}).catch(i=>{console.error("Exec error:",i),n.stderr.write(`Error: ${String(i)}\r
1767
- `),n.exit(1),n.end()})}var rp=require("node:crypto"),cr=require("node:fs"),uo=require("node:path");function Rc(n=process.cwd()){let t=(0,uo.resolve)(n,".ssh-mimic","host_rsa");if((0,cr.existsSync)(t))return(0,cr.readFileSync)(t,"utf8");let e=(0,rp.generateKeyPairSync)("rsa",{modulusLength:2048,privateKeyEncoding:{type:"pkcs1",format:"pem"},publicKeyEncoding:{type:"pkcs1",format:"pem"}}).privateKey;return(0,cr.mkdirSync)((0,uo.dirname)(t),{recursive:!0}),(0,cr.writeFileSync)(t,e,{mode:384}),e}var Wy=Yt(sc(),1);var Pc=!!process.env.DEV_MODE,Sw=Pc?console.log.bind(console):()=>{},xw=Pc?console.warn.bind(console):()=>{},ww=Pc?console.error.bind(console):()=>{};var Iw=ar("SftpMimic");var Tc=ar("SshMimic"),qy=!!process.env.DEV_MODE,ip=qy?console.log.bind(console):()=>{},fo=class extends sp.EventEmitter{port;server;shell;maxAuthAttempts;lockoutDurationMs;authAttempts=new Map;constructor({port:t,hostname:e="typescript-vm",shell:r=new _r(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=Pt(t);this.shell.vfs.exists(e)||(this.shell.vfs.mkdir(e,493),this.shell.vfs.writeFile(`${e}/README.txt`,`Welcome to ${this.shell.hostname}
1768
- `),this.shell.vfs.stopAutoFlush())}async start(){Tc.mark("start");let t=this.shell,e=Rc();return await t.ensureInitialized(),this.server=new op.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 u=a.key;if(!l.some(h=>h.algo===u.algo&&h.data.equals(u.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",(u,f,h)=>{l.cols=h?.cols??l.cols,l.rows=h?.rows??l.rows,u()}),c.on("window-change",(u,f,h)=>{l.cols=h?.cols??l.cols,l.rows=h?.rows??l.rows}),c.on("shell",u=>{let f=u();t?.startInteractiveSession(f,s,o,i,l)}),c.on("exec",(u,f,h)=>{let p=u();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",()=>{ip(`SSH Mimic listening on port ${this.port}`),this.emit("start",{port:this.port}),r(this.port)})})}stop(){Tc.mark("stop"),this.shell.vfs.stopAutoFlush(),this.server&&this.server.close(()=>{ip("SSH Mimic stopped"),this.emit("stop")})}clearLockout(t){this.authAttempts.delete(t)}};var ap=process.env.SSH_MIMIC_HOSTNAME??"typescript-vm",cp=new _r(ap,void 0,{mode:"fs",snapshotPath:".vfs"});cp.addCommand("demo",[],()=>({stdout:"This is a demo command. It does nothing useful.",exitCode:0}));new fo({port:2222,hostname:ap,shell:cp}).start().catch(n=>{console.error("Failed to start SSH 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)});
1760
+ `)}function ip(n,t,e,r,i){Promise.resolve(wt(t,e,r,"exec",Pt(e),i,void 0,Xr(e,r))).then(s=>{s.stdout&&n.write(`${rp(s.stdout)}\r
1761
+ `),s.stderr&&n.stderr.write(`${rp(s.stderr)}\r
1762
+ `),n.exit(s.exitCode??0),n.end()}).catch(s=>{console.error("Exec error:",s),n.stderr.write(`Error: ${String(s)}\r
1763
+ `),n.exit(1),n.end()})}var sp=require("node:crypto"),lr=require("node:fs"),ho=require("node:path");function Tc(n=process.cwd()){let t=(0,ho.resolve)(n,".ssh-mimic","host_rsa");if((0,lr.existsSync)(t))return(0,lr.readFileSync)(t,"utf8");let e=(0,sp.generateKeyPairSync)("rsa",{modulusLength:2048,privateKeyEncoding:{type:"pkcs1",format:"pem"},publicKeyEncoding:{type:"pkcs1",format:"pem"}}).privateKey;return(0,lr.mkdirSync)((0,ho.dirname)(t),{recursive:!0}),(0,lr.writeFileSync)(t,e,{mode:384}),e}var Vy=Yt(ac(),1);var Oc=!!process.env.DEV_MODE,Iw=Oc?console.log.bind(console):()=>{},Cw=Oc?console.warn.bind(console):()=>{},kw=Oc?console.error.bind(console):()=>{};var vw=cr("SftpMimic");var Mc=cr("SshMimic"),zy=!!process.env.DEV_MODE,op=zy?console.log.bind(console):()=>{},po=class extends ap.EventEmitter{port;server;shell;maxAuthAttempts;lockoutDurationMs;authAttempts=new Map;constructor({port:t,hostname:e="typescript-vm",shell:r=new br(e),maxAuthAttempts:i=5,lockoutDurationMs:s=6e4}){super(),Mc.mark("constructor"),this.port=t,this.server=null,this.shell=r,this.maxAuthAttempts=i,this.lockoutDurationMs=s}isLockedOut(t){let e=this.authAttempts.get(t);return e?Date.now()<e.lockedUntil?!0:(e.lockedUntil>0&&this.authAttempts.delete(t),!1):!1}recordFailure(t){let e=this.authAttempts.get(t)??{attempts:0,lockedUntil:0};e.attempts+=1,e.attempts>=this.maxAuthAttempts&&(e.lockedUntil=Date.now()+this.lockoutDurationMs,this.emit("auth:lockout",{ip:t,until:new Date(e.lockedUntil)})),this.authAttempts.set(t,e)}recordSuccess(t){this.authAttempts.delete(t)}ensureHomeDir(t){let e=Pt(t);this.shell.vfs.exists(e)||(this.shell.vfs.mkdir(e,493),this.shell.vfs.writeFile(`${e}/README.txt`,`Welcome to ${this.shell.hostname}
1764
+ `),this.shell.vfs.stopAutoFlush())}async start(){Mc.mark("start");let t=this.shell,e=Tc();return await t.ensureInitialized(),this.server=new cp.Server({hostKeys:[e],ident:`SSH-2.0-${t.hostname}`},r=>{let i="root",s="unknown",o=null;this.emit("client:connect"),r.on("authentication",a=>{let c=a.username||"root";if(s=a.ip??s,this.isLockedOut(s)){this.emit("auth:failure",{username:c,remoteAddress:s,reason:"lockout"}),a.reject();return}if(a.method==="password"){if(!t.users.hasPassword(c)){i=c,o=t.users.registerSession(i,s).id,this.recordSuccess(s),this.emit("auth:success",{username:i,remoteAddress:s}),this.ensureHomeDir(i),a.accept();return}if(!a.password||a.password===""||!t.users.verifyPassword(c,a.password)){this.recordFailure(s),this.emit("auth:failure",{username:c,remoteAddress:s}),a.reject();return}i=c,o=t.users.registerSession(i,s).id,this.recordSuccess(s),this.emit("auth:success",{username:i,remoteAddress:s}),this.ensureHomeDir(i),a.accept();return}if(a.method==="publickey"){let l=t.users.getAuthorizedKeys(c);if(l.length===0){a.reject();return}let u=a.key;if(!l.some(h=>h.algo===u.algo&&h.data.equals(u.data))){this.recordFailure(s),this.emit("auth:failure",{username:c,remoteAddress:s,method:"publickey"}),a.reject();return}a.signature&&(i=c,o=t.users.registerSession(i,s).id,this.recordSuccess(s),this.emit("auth:success",{username:i,remoteAddress:s,method:"publickey"}),this.ensureHomeDir(i)),a.accept();return}a.reject(["password","publickey"])}),r.on("close",()=>{t.users.unregisterSession(o),this.emit("client:disconnect",{user:i}),o=null}),r.on("ready",()=>{r.on("session",a=>{let c=a(),l={cols:80,rows:24};c.on("pty",(u,f,h)=>{l.cols=h?.cols??l.cols,l.rows=h?.rows??l.rows,u()}),c.on("window-change",(u,f,h)=>{l.cols=h?.cols??l.cols,l.rows=h?.rows??l.rows}),c.on("shell",u=>{let f=u();t?.startInteractiveSession(f,i,o,s,l)}),c.on("exec",(u,f,h)=>{let p=u();p&&ip(p,h.command.trim(),i,t.hostname,t)})})})}),new Promise((r,i)=>{this.server?.once("error",s=>i(s)),this.server?.listen(this.port,"0.0.0.0",()=>{op(`SSH Mimic listening on port ${this.port}`),this.emit("start",{port:this.port}),r(this.port)})})}stop(){Mc.mark("stop"),this.shell.vfs.stopAutoFlush(),this.server&&this.server.close(()=>{op("SSH Mimic stopped"),this.emit("stop")})}clearLockout(t){this.authAttempts.delete(t)}};var lp=process.env.SSH_MIMIC_HOSTNAME??"typescript-vm",up=new br(lp,void 0,{mode:"fs",snapshotPath:".vfs"});up.addCommand("demo",[],()=>({stdout:"This is a demo command. It does nothing useful.",exitCode:0}));new po({port:2222,hostname:lp,shell:up}).start().catch(n=>{console.error("Failed to start SSH 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)});