typescript-virtual-container 1.5.3 → 1.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (371) hide show
  1. package/README.md +44 -532
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/SSHMimic/executor.js +23 -5
  4. package/dist/VirtualPackageManager/index.js +10 -0
  5. package/dist/VirtualShell/shell.js +158 -11
  6. package/dist/commands/basename.d.ts +13 -0
  7. package/dist/commands/basename.js +45 -0
  8. package/dist/commands/bc.d.ts +2 -0
  9. package/dist/commands/bc.js +28 -0
  10. package/dist/commands/file.d.ts +8 -0
  11. package/dist/commands/file.js +57 -0
  12. package/dist/commands/fun.d.ts +32 -0
  13. package/dist/commands/fun.js +172 -0
  14. package/dist/commands/ip.d.ts +7 -0
  15. package/dist/commands/ip.js +52 -0
  16. package/dist/commands/jobs.d.ts +4 -0
  17. package/dist/commands/jobs.js +27 -0
  18. package/dist/commands/last.d.ts +13 -0
  19. package/dist/commands/last.js +68 -0
  20. package/dist/commands/manuals-bundle.js +598 -6
  21. package/dist/commands/registry.js +30 -2
  22. package/dist/commands/runtime.js +24 -3
  23. package/dist/commands/set.js +20 -0
  24. package/dist/commands/sh.js +74 -1
  25. package/dist/commands/tput.d.ts +13 -0
  26. package/dist/commands/tput.js +76 -0
  27. package/dist/commands/w.d.ts +7 -0
  28. package/dist/commands/w.js +38 -0
  29. package/dist/utils/expand.d.ts +12 -0
  30. package/dist/utils/expand.js +87 -1
  31. package/package.json +9 -3
  32. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -50
  33. package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -31
  34. package/.github/dependabot.yml +0 -27
  35. package/.github/pull_request_template.md +0 -21
  36. package/.github/workflows/create-pull-request.yml +0 -85
  37. package/.github/workflows/publish.yml +0 -25
  38. package/.github/workflows/test-battery.yml +0 -102
  39. package/.vscode/settings.json +0 -20
  40. package/CODE_OF_CONDUCT.md +0 -39
  41. package/CONTRIBUTING.md +0 -59
  42. package/HONEYPOT.md +0 -358
  43. package/SECURITY.md +0 -33
  44. package/benchmark-results.txt +0 -40
  45. package/benchmark-virtualshell.ts +0 -88
  46. package/biome.json +0 -37
  47. package/build.js +0 -22
  48. package/builds/fortune-nyx-v1.5.3-directbash-k6.1.0.mjs +0 -1764
  49. package/builds/fortune-nyx-v1.5.3-ssh-nosftp.js +0 -1764
  50. package/builds/fortune-nyx-v1.5.3-ssh.cjs +0 -1765
  51. package/builds/fortune-nyx-v1.5.3-web.min.js +0 -17036
  52. package/bun.lock +0 -244
  53. package/docs/.nojekyll +0 -1
  54. package/docs/app.js +0 -1751
  55. package/docs/assets/hierarchy.js +0 -1
  56. package/docs/assets/highlight.css +0 -162
  57. package/docs/assets/icons.js +0 -18
  58. package/docs/assets/icons.svg +0 -1
  59. package/docs/assets/main.js +0 -60
  60. package/docs/assets/navigation.js +0 -1
  61. package/docs/assets/search.js +0 -1
  62. package/docs/assets/style.css +0 -1633
  63. package/docs/classes/HoneyPot.html +0 -31
  64. package/docs/classes/IdleManager.html +0 -162
  65. package/docs/classes/SshClient.html +0 -66
  66. package/docs/classes/VirtualFileSystem.html +0 -279
  67. package/docs/classes/VirtualPackageManager.html +0 -63
  68. package/docs/classes/VirtualSftpServer.html +0 -169
  69. package/docs/classes/VirtualShell.html +0 -285
  70. package/docs/classes/VirtualSshServer.html +0 -182
  71. package/docs/classes/VirtualUserManager.html +0 -276
  72. package/docs/demo.html +0 -82
  73. package/docs/functions/assertDiff.html +0 -6
  74. package/docs/functions/diffSnapshots.html +0 -7
  75. package/docs/functions/formatDiff.html +0 -6
  76. package/docs/functions/getArg.html +0 -13
  77. package/docs/functions/getFlag.html +0 -15
  78. package/docs/functions/ifFlag.html +0 -11
  79. package/docs/hierarchy.html +0 -1
  80. package/docs/index.html +0 -1869
  81. package/docs/interfaces/AuditLogEntry.html +0 -6
  82. package/docs/interfaces/CommandContext.html +0 -22
  83. package/docs/interfaces/CommandResult.html +0 -26
  84. package/docs/interfaces/ExecStream.html +0 -11
  85. package/docs/interfaces/HoneyPotStats.html +0 -16
  86. package/docs/interfaces/IdleManagerOptions.html +0 -7
  87. package/docs/interfaces/InstalledPackage.html +0 -20
  88. package/docs/interfaces/NanoEditorSession.html +0 -8
  89. package/docs/interfaces/PackageDefinition.html +0 -30
  90. package/docs/interfaces/PackageFile.html +0 -8
  91. package/docs/interfaces/PasswordChallenge.html +0 -16
  92. package/docs/interfaces/RemoveOptions.html +0 -4
  93. package/docs/interfaces/ShellEnv.html +0 -6
  94. package/docs/interfaces/ShellModule.html +0 -14
  95. package/docs/interfaces/ShellProperties.html +0 -14
  96. package/docs/interfaces/ShellStream.html +0 -11
  97. package/docs/interfaces/SudoChallenge.html +0 -24
  98. package/docs/interfaces/VfsBaseNode.html +0 -12
  99. package/docs/interfaces/VfsDiff.html +0 -10
  100. package/docs/interfaces/VfsDiffEntry.html +0 -6
  101. package/docs/interfaces/VfsDiffModified.html +0 -10
  102. package/docs/interfaces/VfsDirectoryNode.html +0 -15
  103. package/docs/interfaces/VfsFileNode.html +0 -17
  104. package/docs/interfaces/VfsOptions.html +0 -26
  105. package/docs/interfaces/VfsSnapshot.html +0 -3
  106. package/docs/interfaces/VfsSnapshotBaseNode.html +0 -8
  107. package/docs/interfaces/VfsSnapshotDirectoryNode.html +0 -10
  108. package/docs/interfaces/VfsSnapshotFileNode.html +0 -12
  109. package/docs/interfaces/VirtualActiveSession.html +0 -12
  110. package/docs/interfaces/VirtualSftpServerOptions.html +0 -7
  111. package/docs/interfaces/VirtualShellVfsLike.html +0 -15
  112. package/docs/interfaces/VirtualShellVfsOptions.html +0 -3
  113. package/docs/interfaces/WriteFileOptions.html +0 -6
  114. package/docs/media/LICENSE +0 -21
  115. package/docs/modules.html +0 -1
  116. package/docs/types/ArgParseOptions.html +0 -4
  117. package/docs/types/CommandMode.html +0 -2
  118. package/docs/types/CommandOutcome.html +0 -2
  119. package/docs/types/IdleState.html +0 -1
  120. package/docs/types/VfsNodeStats.html +0 -2
  121. package/docs/types/VfsNodeType.html +0 -2
  122. package/docs/types/VfsPersistenceMode.html +0 -5
  123. package/docs/types/VfsSnapshotNode.html +0 -2
  124. package/examples/README.md +0 -288
  125. package/examples/app.js +0 -1751
  126. package/examples/app.ts +0 -299
  127. package/examples/build.js +0 -27
  128. package/examples/demo.html +0 -33
  129. package/examples/honeypot-audit.ts +0 -180
  130. package/examples/honeypot-export.ts +0 -253
  131. package/examples/honeypot-quickstart.ts +0 -110
  132. package/examples/index.html +0 -82
  133. package/examples/server.js +0 -55
  134. package/polyfills/buffer.js +0 -117
  135. package/polyfills/node_child_process/index.js +0 -2
  136. package/polyfills/node_crypto/index.js +0 -167
  137. package/polyfills/node_events/index.js +0 -9
  138. package/polyfills/node_fs/index.js +0 -202
  139. package/polyfills/node_fs/promises.js +0 -4
  140. package/polyfills/node_os/index.js +0 -9
  141. package/polyfills/node_path/index.js +0 -28
  142. package/polyfills/node_vm/index.js +0 -7
  143. package/polyfills/node_zlib/index.js +0 -3
  144. package/polyfills/process.js +0 -14
  145. package/polyfills/ssh2/index.js +0 -75
  146. package/scripts/build-all.mjs +0 -226
  147. package/scripts/build-names.mjs +0 -43
  148. package/scripts/generate-manuals-bundle.mjs +0 -49
  149. package/scripts/postinstall.js +0 -42
  150. package/scripts/publish-package.sh +0 -70
  151. package/src/Honeypot/index.ts +0 -457
  152. package/src/SSHClient/index.ts +0 -270
  153. package/src/SSHMimic/exec.ts +0 -49
  154. package/src/SSHMimic/executor.ts +0 -251
  155. package/src/SSHMimic/hostKey.ts +0 -21
  156. package/src/SSHMimic/index.ts +0 -337
  157. package/src/SSHMimic/loginBanner.ts +0 -36
  158. package/src/SSHMimic/loginFormat.ts +0 -10
  159. package/src/SSHMimic/prompt.ts +0 -14
  160. package/src/SSHMimic/sftp.ts +0 -883
  161. package/src/VirtualFileSystem/binaryPack.ts +0 -258
  162. package/src/VirtualFileSystem/index.ts +0 -1193
  163. package/src/VirtualFileSystem/internalTypes.ts +0 -43
  164. package/src/VirtualFileSystem/journal.ts +0 -171
  165. package/src/VirtualFileSystem/path.ts +0 -74
  166. package/src/VirtualPackageManager/index.ts +0 -996
  167. package/src/VirtualShell/idleManager.ts +0 -137
  168. package/src/VirtualShell/index.ts +0 -475
  169. package/src/VirtualShell/shell.ts +0 -700
  170. package/src/VirtualShell/shellParser.ts +0 -285
  171. package/src/VirtualUserManager/index.ts +0 -758
  172. package/src/bun.d.ts +0 -1
  173. package/src/commands/adduser.ts +0 -103
  174. package/src/commands/alias.ts +0 -69
  175. package/src/commands/apt.ts +0 -233
  176. package/src/commands/awk.ts +0 -168
  177. package/src/commands/base64.ts +0 -29
  178. package/src/commands/cat.ts +0 -52
  179. package/src/commands/cd.ts +0 -25
  180. package/src/commands/chmod.ts +0 -85
  181. package/src/commands/clear.ts +0 -15
  182. package/src/commands/command-helpers.ts +0 -286
  183. package/src/commands/cp.ts +0 -83
  184. package/src/commands/curl.ts +0 -147
  185. package/src/commands/cut.ts +0 -36
  186. package/src/commands/date.ts +0 -30
  187. package/src/commands/declare.ts +0 -49
  188. package/src/commands/deluser.ts +0 -98
  189. package/src/commands/df.ts +0 -23
  190. package/src/commands/diff.ts +0 -43
  191. package/src/commands/dpkg.ts +0 -180
  192. package/src/commands/du.ts +0 -56
  193. package/src/commands/echo.ts +0 -58
  194. package/src/commands/env.ts +0 -23
  195. package/src/commands/exit.ts +0 -18
  196. package/src/commands/export.ts +0 -34
  197. package/src/commands/find.ts +0 -68
  198. package/src/commands/free.ts +0 -47
  199. package/src/commands/grep.ts +0 -116
  200. package/src/commands/groups.ts +0 -19
  201. package/src/commands/gzip.ts +0 -88
  202. package/src/commands/head.ts +0 -52
  203. package/src/commands/help.ts +0 -152
  204. package/src/commands/helpers.ts +0 -234
  205. package/src/commands/history.ts +0 -34
  206. package/src/commands/hostname.ts +0 -14
  207. package/src/commands/htop.ts +0 -20
  208. package/src/commands/id.ts +0 -19
  209. package/src/commands/index.ts +0 -9
  210. package/src/commands/kill.ts +0 -19
  211. package/src/commands/ln.ts +0 -71
  212. package/src/commands/ls.ts +0 -243
  213. package/src/commands/lsb-release.ts +0 -63
  214. package/src/commands/man.ts +0 -31
  215. package/src/commands/manuals/adduser.txt +0 -11
  216. package/src/commands/manuals/apt-cache.txt +0 -12
  217. package/src/commands/manuals/apt.txt +0 -20
  218. package/src/commands/manuals/awk.txt +0 -13
  219. package/src/commands/manuals/cat.txt +0 -14
  220. package/src/commands/manuals/cd.txt +0 -16
  221. package/src/commands/manuals/chmod.txt +0 -16
  222. package/src/commands/manuals/clear.txt +0 -10
  223. package/src/commands/manuals/cp.txt +0 -10
  224. package/src/commands/manuals/curl.txt +0 -20
  225. package/src/commands/manuals/date.txt +0 -14
  226. package/src/commands/manuals/declare.txt +0 -12
  227. package/src/commands/manuals/deluser.txt +0 -10
  228. package/src/commands/manuals/df.txt +0 -10
  229. package/src/commands/manuals/dpkg-query.txt +0 -11
  230. package/src/commands/manuals/dpkg.txt +0 -14
  231. package/src/commands/manuals/du.txt +0 -11
  232. package/src/commands/manuals/echo.txt +0 -11
  233. package/src/commands/manuals/false.txt +0 -10
  234. package/src/commands/manuals/find.txt +0 -11
  235. package/src/commands/manuals/free.txt +0 -12
  236. package/src/commands/manuals/grep.txt +0 -13
  237. package/src/commands/manuals/groups.txt +0 -10
  238. package/src/commands/manuals/gzip.txt +0 -11
  239. package/src/commands/manuals/head.txt +0 -10
  240. package/src/commands/manuals/help.txt +0 -11
  241. package/src/commands/manuals/history.txt +0 -11
  242. package/src/commands/manuals/hostname.txt +0 -10
  243. package/src/commands/manuals/id.txt +0 -10
  244. package/src/commands/manuals/kill.txt +0 -13
  245. package/src/commands/manuals/ls.txt +0 -20
  246. package/src/commands/manuals/lsb_release.txt +0 -14
  247. package/src/commands/manuals/mkdir.txt +0 -10
  248. package/src/commands/manuals/mv.txt +0 -10
  249. package/src/commands/manuals/nano.txt +0 -11
  250. package/src/commands/manuals/neofetch.txt +0 -10
  251. package/src/commands/manuals/node.txt +0 -13
  252. package/src/commands/manuals/npm.txt +0 -13
  253. package/src/commands/manuals/npx.txt +0 -13
  254. package/src/commands/manuals/passwd.txt +0 -11
  255. package/src/commands/manuals/ping.txt +0 -10
  256. package/src/commands/manuals/printf.txt +0 -11
  257. package/src/commands/manuals/ps.txt +0 -10
  258. package/src/commands/manuals/pwd.txt +0 -10
  259. package/src/commands/manuals/python3.txt +0 -13
  260. package/src/commands/manuals/readlink.txt +0 -10
  261. package/src/commands/manuals/return.txt +0 -10
  262. package/src/commands/manuals/rm.txt +0 -10
  263. package/src/commands/manuals/sed.txt +0 -11
  264. package/src/commands/manuals/set.txt +0 -11
  265. package/src/commands/manuals/shift.txt +0 -10
  266. package/src/commands/manuals/sleep.txt +0 -10
  267. package/src/commands/manuals/sort.txt +0 -12
  268. package/src/commands/manuals/source.txt +0 -11
  269. package/src/commands/manuals/ssh.txt +0 -11
  270. package/src/commands/manuals/stat.txt +0 -10
  271. package/src/commands/manuals/su.txt +0 -13
  272. package/src/commands/manuals/sudo.txt +0 -11
  273. package/src/commands/manuals/tail.txt +0 -10
  274. package/src/commands/manuals/tar.txt +0 -19
  275. package/src/commands/manuals/tee.txt +0 -10
  276. package/src/commands/manuals/test.txt +0 -11
  277. package/src/commands/manuals/touch.txt +0 -11
  278. package/src/commands/manuals/tr.txt +0 -10
  279. package/src/commands/manuals/trap.txt +0 -10
  280. package/src/commands/manuals/true.txt +0 -10
  281. package/src/commands/manuals/type.txt +0 -10
  282. package/src/commands/manuals/uname.txt +0 -12
  283. package/src/commands/manuals/uniq.txt +0 -12
  284. package/src/commands/manuals/unset.txt +0 -10
  285. package/src/commands/manuals/uptime.txt +0 -11
  286. package/src/commands/manuals/wc.txt +0 -12
  287. package/src/commands/manuals/wget.txt +0 -12
  288. package/src/commands/manuals/which.txt +0 -10
  289. package/src/commands/manuals/whoami.txt +0 -10
  290. package/src/commands/manuals/xargs.txt +0 -10
  291. package/src/commands/manuals-bundle.ts +0 -898
  292. package/src/commands/mkdir.ts +0 -31
  293. package/src/commands/mv.ts +0 -50
  294. package/src/commands/nano.ts +0 -38
  295. package/src/commands/neofetch.ts +0 -53
  296. package/src/commands/node.ts +0 -341
  297. package/src/commands/npm.ts +0 -132
  298. package/src/commands/passwd.ts +0 -50
  299. package/src/commands/ping.ts +0 -32
  300. package/src/commands/printf.ts +0 -129
  301. package/src/commands/ps.ts +0 -58
  302. package/src/commands/pwd.ts +0 -9
  303. package/src/commands/python.ts +0 -2229
  304. package/src/commands/read.ts +0 -46
  305. package/src/commands/registry.ts +0 -249
  306. package/src/commands/rm.ts +0 -42
  307. package/src/commands/runtime.ts +0 -421
  308. package/src/commands/sed.ts +0 -68
  309. package/src/commands/seq.ts +0 -43
  310. package/src/commands/set.ts +0 -29
  311. package/src/commands/sh.ts +0 -467
  312. package/src/commands/shift.ts +0 -63
  313. package/src/commands/sleep.ts +0 -20
  314. package/src/commands/sort.ts +0 -46
  315. package/src/commands/source.ts +0 -52
  316. package/src/commands/stat.ts +0 -61
  317. package/src/commands/su.ts +0 -72
  318. package/src/commands/sudo.ts +0 -76
  319. package/src/commands/tail.ts +0 -53
  320. package/src/commands/tar.ts +0 -102
  321. package/src/commands/tee.ts +0 -36
  322. package/src/commands/test.ts +0 -137
  323. package/src/commands/touch.ts +0 -28
  324. package/src/commands/tr.ts +0 -70
  325. package/src/commands/tree.ts +0 -20
  326. package/src/commands/true.ts +0 -27
  327. package/src/commands/type.ts +0 -48
  328. package/src/commands/uname.ts +0 -29
  329. package/src/commands/uniq.ts +0 -39
  330. package/src/commands/unset.ts +0 -17
  331. package/src/commands/uptime.ts +0 -54
  332. package/src/commands/wc.ts +0 -55
  333. package/src/commands/wget.ts +0 -148
  334. package/src/commands/which.ts +0 -37
  335. package/src/commands/who.ts +0 -25
  336. package/src/commands/whoami.ts +0 -14
  337. package/src/commands/xargs.ts +0 -31
  338. package/src/index.ts +0 -67
  339. package/src/modules/linuxRootfs.ts +0 -1961
  340. package/src/modules/neofetch.ts +0 -358
  341. package/src/modules/shellInteractive.ts +0 -57
  342. package/src/modules/shellRuntime.ts +0 -76
  343. package/src/self-standalone.ts +0 -542
  344. package/src/standalone-wo-sftp.ts +0 -38
  345. package/src/standalone.ts +0 -72
  346. package/src/types/commands.ts +0 -146
  347. package/src/types/pipeline.ts +0 -52
  348. package/src/types/streams.ts +0 -32
  349. package/src/types/tar-stream.d.ts +0 -38
  350. package/src/types/vfs.ts +0 -98
  351. package/src/utils/expand.ts +0 -491
  352. package/src/utils/perfLogger.ts +0 -72
  353. package/src/utils/tokenize.ts +0 -98
  354. package/src/utils/vfsDiff.ts +0 -275
  355. package/tests/command-helpers.test.ts +0 -116
  356. package/tests/commands-admin-net.test.ts +0 -441
  357. package/tests/commands-advanced.test.ts +0 -456
  358. package/tests/commands-core.test.ts +0 -562
  359. package/tests/commands-missing.test.ts +0 -570
  360. package/tests/commands-specific-units.test.ts +0 -327
  361. package/tests/commands-text-sys.test.ts +0 -445
  362. package/tests/expand.test.ts +0 -170
  363. package/tests/helpers.test.ts +0 -97
  364. package/tests/new-features.test.ts +0 -1036
  365. package/tests/parser-executor.test.ts +0 -37
  366. package/tests/sftp.test.ts +0 -323
  367. package/tests/ssh-exec.test.ts +0 -45
  368. package/tests/test-helper.ts +0 -79
  369. package/tests/users.test.ts +0 -86
  370. package/tsconfig.json +0 -49
  371. package/typedoc.json +0 -47
@@ -1,167 +0,0 @@
1
- // ─── SHA-256 (pure JS) ───────────────────────────────────────────────────────
2
- const K = new Uint32Array([
3
- 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,
4
- 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,
5
- 0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,
6
- 0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,
7
- 0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,
8
- 0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,
9
- 0x19a4c116,0x1e376c085,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,
10
- 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2,
11
- ]);
12
-
13
- function sha256(data) {
14
- const msg = data instanceof Uint8Array ? data : new TextEncoder().encode(data);
15
- const bits = msg.length * 8;
16
- const padLen = Math.ceil((msg.length + 9) / 64) * 64;
17
- const padded = new Uint8Array(padLen);
18
- padded.set(msg);
19
- padded[msg.length] = 0x80;
20
- const dv0 = new DataView(padded.buffer);
21
- dv0.setUint32(padLen - 4, bits >>> 0, false);
22
-
23
- let h0=0x6a09e667, h1=0xbb67ae85, h2=0x3c6ef372, h3=0xa54ff53a,
24
- h4=0x510e527f, h5=0x9b05688c, h6=0x1f83d9ab, h7=0x5be0cd19;
25
-
26
- const w = new Uint32Array(64);
27
- const dv = new DataView(padded.buffer);
28
- for (let i = 0; i < padLen; i += 64) {
29
- for (let j = 0; j < 16; j++) w[j] = dv.getUint32(i + j * 4, false);
30
- for (let j = 16; j < 64; j++) {
31
- const s0 = (w[j-15]>>>7|w[j-15]<<25)^(w[j-15]>>>18|w[j-15]<<14)^(w[j-15]>>>3);
32
- const s1 = (w[j-2]>>>17|w[j-2]<<15)^(w[j-2]>>>19|w[j-2]<<13)^(w[j-2]>>>10);
33
- w[j] = (w[j-16] + s0 + w[j-7] + s1) | 0;
34
- }
35
- let a=h0,b=h1,c=h2,d=h3,e=h4,f=h5,g=h6,hh=h7;
36
- for (let j = 0; j < 64; j++) {
37
- const S1 = (e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7);
38
- const ch = (e&f)^(~e&g);
39
- const t1 = (hh + S1 + ch + K[j] + w[j]) | 0;
40
- const S0 = (a>>>2|a<<30)^(a>>>13|a<<19)^(a>>>22|a<<10);
41
- const maj = (a&b)^(a&c)^(b&c);
42
- const t2 = (S0 + maj) | 0;
43
- hh=g; g=f; f=e; e=(d+t1)|0; d=c; c=b; b=a; a=(t1+t2)|0;
44
- }
45
- h0=(h0+a)|0; h1=(h1+b)|0; h2=(h2+c)|0; h3=(h3+d)|0;
46
- h4=(h4+e)|0; h5=(h5+f)|0; h6=(h6+g)|0; h7=(h7+hh)|0;
47
- }
48
-
49
- const out = new Uint8Array(32);
50
- const odv = new DataView(out.buffer);
51
- [h0,h1,h2,h3,h4,h5,h6,h7].forEach((v,i) => odv.setUint32(i*4, v, false));
52
- return out;
53
- }
54
-
55
- // ─── HMAC-SHA256 ─────────────────────────────────────────────────────────────
56
- function hmacSha256(key, data) {
57
- const BLOCK = 64;
58
- let k = key instanceof Uint8Array ? key : new TextEncoder().encode(key);
59
- if (k.length > BLOCK) k = sha256(k);
60
- const kpad = new Uint8Array(BLOCK);
61
- kpad.set(k);
62
- const ipad = kpad.map(b => b ^ 0x36);
63
- const opad = kpad.map(b => b ^ 0x5c);
64
- const inner = new Uint8Array(BLOCK + data.length);
65
- inner.set(ipad); inner.set(data, BLOCK);
66
- const outer = new Uint8Array(BLOCK + 32);
67
- outer.set(opad); outer.set(sha256(inner), BLOCK);
68
- return sha256(outer);
69
- }
70
-
71
- // ─── PBKDF2-HMAC-SHA256 (sync) ───────────────────────────────────────────────
72
- function pbkdf2Sync(password, salt, iterations, keylen) {
73
- const pw = password instanceof Uint8Array ? password : new TextEncoder().encode(password);
74
- const sl = salt instanceof Uint8Array ? salt : new TextEncoder().encode(salt);
75
- const hlen = 32;
76
- const blocks = Math.ceil(keylen / hlen);
77
- const dk = new Uint8Array(keylen);
78
-
79
- for (let i = 1; i <= blocks; i++) {
80
- const ibuf = new Uint8Array(4);
81
- new DataView(ibuf.buffer).setUint32(0, i, false);
82
- const saltI = new Uint8Array(sl.length + 4);
83
- saltI.set(sl);
84
- saltI.set(ibuf, sl.length);
85
-
86
- let U = hmacSha256(pw, saltI);
87
- const T = new Uint8Array(U);
88
- for (let j = 1; j < iterations; j++) {
89
- U = hmacSha256(pw, U);
90
- for (let k = 0; k < hlen; k++) T[k] ^= U[k];
91
- }
92
- const offset = (i - 1) * hlen;
93
- dk.set(T.slice(0, keylen - offset), offset);
94
- }
95
- return dk;
96
- }
97
-
98
- // ─── Exports ─────────────────────────────────────────────────────────────────
99
- export function randomBytes(n) {
100
- const a = new Uint8Array(n);
101
- crypto.getRandomValues(a);
102
- return a;
103
- }
104
-
105
- export function randomUUID() {
106
- return crypto.randomUUID
107
- ? crypto.randomUUID()
108
- : ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
109
- (c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16));
110
- }
111
-
112
- export function createHash(alg) {
113
- const chunks = [];
114
- return {
115
- update(d) {
116
- chunks.push(d instanceof Uint8Array ? d : new TextEncoder().encode(String(d)));
117
- return this;
118
- },
119
- digest(enc = 'hex') {
120
- const total = chunks.reduce((s, c) => s + c.length, 0);
121
- const buf = new Uint8Array(total);
122
- let off = 0;
123
- for (const c of chunks) { buf.set(c, off); off += c.length; }
124
- const hash = sha256(buf);
125
- if (enc === 'hex') return Array.from(hash).map(b => b.toString(16).padStart(2,'0')).join('');
126
- if (enc === 'base64') return btoa(String.fromCharCode(...hash));
127
- return hash;
128
- },
129
- };
130
- }
131
-
132
- export function scryptSync(password, salt, keylen, options = {}) {
133
- const N = options.N ?? 16384;
134
- const iterations = Math.max(1000, Math.round(Math.log2(N) * 1000));
135
- const pw = typeof password === 'string' ? new TextEncoder().encode(password) : password;
136
- const sl = typeof salt === 'string' ? new TextEncoder().encode(salt) : salt;
137
- return pbkdf2Sync(pw, sl, iterations, keylen);
138
- }
139
-
140
- export function timingSafeEqual(a, b) {
141
- if (a.length !== b.length) return false;
142
- let diff = 0;
143
- for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
144
- return diff === 0;
145
- }
146
-
147
- export function generateKeyPairSync() {
148
- throw new Error('generateKeyPairSync is not implemented in this environment');
149
- }
150
-
151
- export function createHmac() {
152
- throw new Error('createHmac is not implemented in this environment');
153
- }
154
-
155
- export function createCipheriv() {
156
- throw new Error('createCipheriv is not implemented in this environment');
157
- }
158
-
159
- export function createDecipheriv() {
160
- throw new Error('createDecipheriv is not implemented in this environment');
161
- }
162
-
163
- export function createSign() {
164
- throw new Error('createSign is not implemented in this environment');
165
- }
166
-
167
- export default { randomBytes, randomUUID, createHash, scryptSync, timingSafeEqual, generateKeyPairSync, createHmac, createCipheriv, createDecipheriv, createSign };
@@ -1,9 +0,0 @@
1
- export class EventEmitter {
2
- constructor(){ this._events = Object.create(null); }
3
- on(ev, fn){ (this._events[ev] ||= []).push(fn); return this; }
4
- addListener(ev, fn){ return this.on(ev, fn); }
5
- emit(ev, ...args){ const fns = this._events[ev] || []; for (const f of fns) try{ f(...args);}catch(e){} return fns.length>0; }
6
- removeListener(ev, fn){ if(!this._events[ev]) return; this._events[ev]=this._events[ev].filter(x=>x!==fn); }
7
- }
8
-
9
- export default EventEmitter;
@@ -1,202 +0,0 @@
1
- // ── In-memory cache backed by IndexedDB (async writes, sync reads from cache) ──
2
-
3
- const DB_NAME = 'vfs-fs-shim';
4
- const STORE = 'files';
5
- let db = null;
6
-
7
- function openDB() {
8
- if (db) return Promise.resolve(db);
9
- return new Promise((resolve, reject) => {
10
- const req = indexedDB.open(DB_NAME, 1);
11
- req.onupgradeneeded = e => e.target.result.createObjectStore(STORE);
12
- req.onsuccess = e => { db = e.target.result; resolve(db); };
13
- req.onerror = e => reject(e.target.error);
14
- });
15
- }
16
-
17
- // Sync cache (path → Uint8Array | null)
18
- const memCache = new Map();
19
-
20
- // Preload all keys into memCache at startup
21
- openDB().then(db => {
22
- const tx = db.transaction(STORE, 'readonly');
23
- const req = tx.objectStore(STORE).openCursor();
24
- req.onsuccess = e => {
25
- const cursor = e.target.result;
26
- if (!cursor) return;
27
- memCache.set(cursor.key, cursor.value);
28
- cursor.continue();
29
- };
30
- });
31
-
32
- function idbSet(path, value) {
33
- openDB().then(db => {
34
- const tx = db.transaction(STORE, 'readwrite');
35
- if (value === null) tx.objectStore(STORE).delete(path);
36
- else tx.objectStore(STORE).put(value, path);
37
- });
38
- }
39
-
40
- // ── Helpers ──────────────────────────────────────────────────────────────────
41
-
42
- function toBytes(data, encoding = 'utf8') {
43
- if (data instanceof Uint8Array) return data;
44
- if (typeof data === 'string') {
45
- if (encoding === 'hex') {
46
- const arr = new Uint8Array(data.length / 2);
47
- for (let i = 0; i < arr.length; i++)
48
- arr[i] = parseInt(data.slice(i*2, i*2+2), 16);
49
- return arr;
50
- }
51
- return new TextEncoder().encode(data);
52
- }
53
- return new Uint8Array(data);
54
- }
55
-
56
- function fromBytes(bytes, encoding = 'utf8') {
57
- if (!encoding || encoding === 'utf8') return new TextDecoder().decode(bytes);
58
- if (encoding === 'hex') return Array.from(bytes).map(b => b.toString(16).padStart(2,'0')).join('');
59
- if (encoding === 'base64') return btoa(String.fromCharCode(...bytes));
60
- return new TextDecoder().decode(bytes);
61
- }
62
-
63
- function parentPath(p) {
64
- const parts = p.split('/').filter(Boolean);
65
- parts.pop();
66
- return '/' + parts.join('/');
67
- }
68
-
69
- // ── Sync API (reads from memCache) ───────────────────────────────────────────
70
-
71
- export function existsSync(path) {
72
- return memCache.has(path);
73
- }
74
-
75
- export function readFileSync(path, optionsOrEncoding) {
76
- if (!memCache.has(path)) throw Object.assign(new Error(`ENOENT: no such file: ${path}`), { code: 'ENOENT' });
77
- const bytes = memCache.get(path);
78
- if (bytes === '__DIR__') throw Object.assign(new Error(`EISDIR: ${path}`), { code: 'EISDIR' });
79
- const enc = typeof optionsOrEncoding === 'string' ? optionsOrEncoding : optionsOrEncoding?.encoding;
80
- if (enc) return fromBytes(bytes, enc);
81
- return globalThis.Buffer.from(bytes);
82
- }
83
-
84
- export function writeFileSync(path, data, optionsOrEncoding) {
85
- const enc = typeof optionsOrEncoding === 'string' ? optionsOrEncoding : optionsOrEncoding?.encoding;
86
- const bytes = toBytes(data, enc);
87
- memCache.set(path, bytes);
88
- idbSet(path, bytes);
89
- }
90
-
91
- export function appendFileSync(path, data, optionsOrEncoding) {
92
- const enc = typeof optionsOrEncoding === 'string' ? optionsOrEncoding : optionsOrEncoding?.encoding;
93
- const newBytes = toBytes(data, enc);
94
- const existing = memCache.has(path) ? memCache.get(path) : new Uint8Array(0);
95
- const merged = new Uint8Array(existing.length + newBytes.length);
96
- merged.set(existing);
97
- merged.set(newBytes, existing.length);
98
- memCache.set(path, merged);
99
- idbSet(path, merged);
100
- }
101
-
102
- export function unlinkSync(path) {
103
- memCache.delete(path);
104
- idbSet(path, null);
105
- }
106
-
107
- export function rmSync(path, options = {}) {
108
- if (options.recursive) {
109
- for (const key of [...memCache.keys()]) {
110
- if (key === path || key.startsWith(path + '/')) {
111
- memCache.delete(key);
112
- idbSet(key, null);
113
- }
114
- }
115
- } else {
116
- unlinkSync(path);
117
- }
118
- }
119
-
120
- export function mkdirSync(path, options = {}) {
121
- if (options.recursive) {
122
- // ensure all parents exist
123
- const parts = path.split('/').filter(Boolean);
124
- let cur = '';
125
- for (const p of parts) {
126
- cur += '/' + p;
127
- if (!memCache.has(cur)) { memCache.set(cur, '__DIR__'); idbSet(cur, '__DIR__'); }
128
- }
129
- } else {
130
- memCache.set(path, '__DIR__');
131
- idbSet(path, '__DIR__');
132
- }
133
- }
134
-
135
- export function readdirSync(path) {
136
- const prefix = path.endsWith('/') ? path : path + '/';
137
- return [...memCache.keys()]
138
- .filter(k => k.startsWith(prefix) && k.slice(prefix.length).split('/').length === 1)
139
- .map(k => k.slice(prefix.length));
140
- }
141
-
142
- export function statSync(path) {
143
- if (!memCache.has(path)) throw Object.assign(new Error(`ENOENT: ${path}`), { code: 'ENOENT' });
144
- const val = memCache.get(path);
145
- const isDir = val === '__DIR__';
146
- return {
147
- isDirectory: () => isDir,
148
- isFile: () => !isDir,
149
- size: isDir ? 0 : val.length,
150
- };
151
- }
152
-
153
- // ── fd stubs (journal uses these) ────────────────────────────────────────────
154
-
155
- const fdMap = new Map();
156
- let fdCounter = 10;
157
-
158
- export const constants = { O_WRONLY: 1, O_CREAT: 64, O_APPEND: 1024 };
159
-
160
- export function openSync(path, flags) {
161
- const fd = fdCounter++;
162
- const append = (flags & constants.O_APPEND) !== 0;
163
- const existing = memCache.has(path) ? memCache.get(path) : new Uint8Array(0);
164
- fdMap.set(fd, { path, data: append ? existing : new Uint8Array(0) });
165
- return fd;
166
- }
167
-
168
- export function writeSync(fd, buf) {
169
- const entry = fdMap.get(fd);
170
- if (!entry) return;
171
- const merged = new Uint8Array(entry.data.length + buf.length);
172
- merged.set(entry.data);
173
- merged.set(buf, entry.data.length);
174
- entry.data = merged;
175
- }
176
-
177
- export function closeSync(fd) {
178
- const entry = fdMap.get(fd);
179
- if (!entry) return;
180
- memCache.set(entry.path, entry.data);
181
- idbSet(entry.path, entry.data);
182
- fdMap.delete(fd);
183
- }
184
-
185
- export const ready = openDB().then(db => new Promise(resolve => {
186
- const tx = db.transaction(STORE, 'readonly');
187
- const req = tx.objectStore(STORE).openCursor();
188
- req.onsuccess = e => {
189
- const cursor = e.target.result;
190
- if (!cursor) return resolve(true);
191
- memCache.set(cursor.key, cursor.value);
192
- cursor.continue();
193
- };
194
- }));
195
-
196
- globalThis.__fsReady__ = ready;
197
-
198
- export default {
199
- existsSync, readFileSync, writeFileSync, appendFileSync,
200
- unlinkSync, rmSync, mkdirSync, readdirSync, statSync,
201
- openSync, writeSync, closeSync, constants, ready
202
- };
@@ -1,4 +0,0 @@
1
- export async function readFile(){ throw new Error('node:fs/promises.readFile is not supported in browser'); }
2
- export async function writeFile(){ throw new Error('node:fs/promises.writeFile is not supported in browser'); }
3
- export async function unlink(){ throw new Error('node:fs/promises.unlink is not supported in browser'); }
4
- export default { readFile, writeFile, unlink };
@@ -1,9 +0,0 @@
1
- export function totalmem(){ try{ return navigator?.deviceMemory? navigator.deviceMemory*1024*1024 : 1024*1024*1024; }catch(e){return 1024*1024*1024;} }
2
- export function freemem(){ return Math.floor(totalmem()*0.5); }
3
- export function cpus(){ return [{ model: 'web-cpu', speed: 1000 }]; }
4
- export function platform(){ return 'browser'; }
5
- export function type(){ return 'web'; }
6
- export function arch(){ return 'x86_64'; }
7
- export function release(){ return 'web-release'; }
8
- export function uptime(){ return Math.floor(performance.now()/1000); }
9
- export default { totalmem, freemem, cpus, platform, type, arch, release, uptime };
@@ -1,28 +0,0 @@
1
- export const posix = {
2
- basename(p) { const parts = p.split('/').filter(Boolean); return parts.length ? parts[parts.length - 1] : ''; },
3
- dirname(p) { if (!p) return '.'; const parts = p.split('/').filter(Boolean); parts.pop(); return parts.length ? '/' + parts.join('/') : '/'; },
4
- join(...parts) { return parts.join('/').replace(/\/+/g, '/'); },
5
- resolve(...parts) { // naive resolve
6
- const joined = parts.join('/');
7
- if (joined.startsWith('/')) return joined;
8
- return '/' + joined;
9
- },
10
- normalize(p) {
11
- const parts = p.split('/');
12
- const stack = [];
13
- for (const part of parts) {
14
- if (part === '..') stack.pop();
15
- else if (part && part !== '.') stack.push(part);
16
- }
17
- return (p.startsWith('/') ? '/' : '') + stack.join('/') || '.';
18
- }
19
- };
20
- export function basename(p) { return posix.basename(p); }
21
- export function dirname(p) { return posix.dirname(p); }
22
- export function resolve(...parts) { return posix.resolve(...parts); }
23
- export function join(...parts) {
24
- return parts.join('/').replace(/\/+/g, '/');
25
- }
26
- export function normalize(p) {
27
- return posix.normalize(p);
28
- }
@@ -1,7 +0,0 @@
1
- // Minimal vm shim: execute code in Function scope (no sandbox guarantees)
2
- export default function runInVm(code, options){
3
- const fn = new Function('exports','require','module','__filename','__dirname', code);
4
- const module = { exports: {} };
5
- fn(module.exports, ()=>{throw new Error('require not supported in vm shim')}, module, '', '');
6
- return module.exports;
7
- }
@@ -1,3 +0,0 @@
1
- export function gzipSync(buf){ return buf; }
2
- export function gunzipSync(buf){ return buf; }
3
- export default { gzipSync, gunzipSync };
@@ -1,14 +0,0 @@
1
- globalThis.startedat = Date.now();
2
- export const process = {
3
- env: { NODE_ENV: 'production' },
4
- version: 'v20.0.0',
5
- platform: 'browser',
6
- browser: true,
7
- argv: [],
8
- cwd: () => '/',
9
- exit: () => {},
10
- nextTick: (fn, ...args) => queueMicrotask(() => fn(...args)),
11
- memoryUsage: () => ({ rss: 0, heapTotal: 0, heapUsed: 0, external: 0 }),
12
- uptime: () => (Date.now() - globalThis.startedat) / 1000,
13
- };
14
- globalThis.process = process;
@@ -1,75 +0,0 @@
1
- // ssh2 polyfill — browser stub. All methods throw NotImplemented.
2
-
3
- function notImpl(name) {
4
- return function() {
5
- throw new Error(`ssh2: ${name} not implemented in browser`);
6
- };
7
- }
8
-
9
- // ── Client ────────────────────────────────────────────────────────────────────
10
-
11
- export class Client {
12
- connect() { notImpl('Client.connect')(); }
13
- end() { notImpl('Client.end')(); }
14
- destroy() { notImpl('Client.destroy')(); }
15
- exec() { notImpl('Client.exec')(); }
16
- shell() { notImpl('Client.shell')(); }
17
- subsys() { notImpl('Client.subsys')(); }
18
- sftp() { notImpl('Client.sftp')(); }
19
- forwardIn() { notImpl('Client.forwardIn')(); }
20
- unforwardIn() { notImpl('Client.unforwardIn')(); }
21
- forwardOut() { notImpl('Client.forwardOut')(); }
22
- openssh_noMoreSessions(){ notImpl('Client.openssh_noMoreSessions')(); }
23
- openssh_forwardInStreamLocal() { notImpl('Client.openssh_forwardInStreamLocal')(); }
24
- openssh_unforwardInStreamLocal(){ notImpl('Client.openssh_unforwardInStreamLocal')(); }
25
- openssh_forwardOutStreamLocal() { notImpl('Client.openssh_forwardOutStreamLocal')(); }
26
- on() { return this; }
27
- once() { return this; }
28
- off() { return this; }
29
- emit() { return false; }
30
- removeListener() { return this; }
31
- }
32
-
33
- // ── Server ────────────────────────────────────────────────────────────────────
34
-
35
- export class Server {
36
- constructor() { notImpl('Server constructor')(); }
37
- listen() { notImpl('Server.listen')(); }
38
- close() { notImpl('Server.close')(); }
39
- on() { return this; }
40
- once() { return this; }
41
- off() { return this; }
42
- emit() { return false; }
43
- removeListener() { return this; }
44
- }
45
-
46
- // ── utils ─────────────────────────────────────────────────────────────────────
47
-
48
- export const utils = {
49
- generateKeyPair: notImpl('utils.generateKeyPair'),
50
- generateKeyPairSync: notImpl('utils.generateKeyPairSync'),
51
- parseKey: notImpl('utils.parseKey'),
52
- parsePrivateKey: notImpl('utils.parsePrivateKey'),
53
- parsePublicKey: notImpl('utils.parsePublicKey'),
54
- decryptKey: notImpl('utils.decryptKey'),
55
- sftp: {
56
- OPEN_MODE: {},
57
- STATUS_CODE: {},
58
- flagsToString: notImpl('utils.sftp.flagsToString'),
59
- stringToFlags: notImpl('utils.sftp.stringToFlags'),
60
- },
61
- };
62
-
63
- // ── HTTPAgent stubs ───────────────────────────────────────────────────────────
64
-
65
- export class HTTPAgent {
66
- constructor() { notImpl('HTTPAgent constructor')(); }
67
- }
68
-
69
- export class HTTPSAgent {
70
- constructor() { notImpl('HTTPSAgent constructor')(); }
71
- }
72
-
73
- // ── default export (mirrors ssh2 CommonJS shape) ─────────────────────────────
74
-
75
- export default { Client, Server, utils, HTTPAgent, HTTPSAgent };