toolcraft 0.0.749 → 0.0.751

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 (374) hide show
  1. package/composition.json +23 -3
  2. package/dist/composition.json +23 -3
  3. package/dist/human-in-loop/approvals-commands.d.ts +1 -1
  4. package/dist/index.d.ts +1 -262
  5. package/dist/index.js +1 -573
  6. package/dist/runtime-platform.d.ts +2 -0
  7. package/dist/runtime-platform.js +2 -0
  8. package/dist/runtime-platform.workerd.d.ts +3 -0
  9. package/dist/runtime-platform.workerd.js +10 -0
  10. package/dist/runtime.d.ts +262 -0
  11. package/dist/runtime.js +576 -0
  12. package/node_modules/@noble/hashes/LICENSE +21 -0
  13. package/node_modules/@noble/hashes/README.md +478 -0
  14. package/node_modules/@noble/hashes/_blake.d.ts +20 -0
  15. package/node_modules/@noble/hashes/_blake.js +59 -0
  16. package/node_modules/@noble/hashes/_md.d.ts +95 -0
  17. package/node_modules/@noble/hashes/_md.js +209 -0
  18. package/node_modules/@noble/hashes/_u64.d.ts +36 -0
  19. package/node_modules/@noble/hashes/_u64.js +77 -0
  20. package/node_modules/@noble/hashes/argon2.d.ts +148 -0
  21. package/node_modules/@noble/hashes/argon2.js +577 -0
  22. package/node_modules/@noble/hashes/blake1.d.ts +162 -0
  23. package/node_modules/@noble/hashes/blake1.js +630 -0
  24. package/node_modules/@noble/hashes/blake2.d.ts +203 -0
  25. package/node_modules/@noble/hashes/blake2.js +573 -0
  26. package/node_modules/@noble/hashes/blake3.d.ts +68 -0
  27. package/node_modules/@noble/hashes/blake3.js +310 -0
  28. package/node_modules/@noble/hashes/eskdf.d.ts +91 -0
  29. package/node_modules/@noble/hashes/eskdf.js +225 -0
  30. package/node_modules/@noble/hashes/hkdf.d.ts +70 -0
  31. package/node_modules/@noble/hashes/hkdf.js +152 -0
  32. package/node_modules/@noble/hashes/hmac.d.ts +50 -0
  33. package/node_modules/@noble/hashes/hmac.js +93 -0
  34. package/node_modules/@noble/hashes/index.d.ts +1 -0
  35. package/node_modules/@noble/hashes/index.js +34 -0
  36. package/node_modules/@noble/hashes/legacy.d.ts +107 -0
  37. package/node_modules/@noble/hashes/legacy.js +348 -0
  38. package/node_modules/@noble/hashes/package.json +91 -0
  39. package/node_modules/@noble/hashes/pbkdf2.d.ts +66 -0
  40. package/node_modules/@noble/hashes/pbkdf2.js +176 -0
  41. package/node_modules/@noble/hashes/scrypt.d.ts +98 -0
  42. package/node_modules/@noble/hashes/scrypt.js +304 -0
  43. package/node_modules/@noble/hashes/sha2.d.ts +176 -0
  44. package/node_modules/@noble/hashes/sha2.js +446 -0
  45. package/node_modules/@noble/hashes/sha3-addons.d.ts +533 -0
  46. package/node_modules/@noble/hashes/sha3-addons.js +973 -0
  47. package/node_modules/@noble/hashes/sha3.d.ts +208 -0
  48. package/node_modules/@noble/hashes/sha3.js +475 -0
  49. package/node_modules/@noble/hashes/src/_blake.ts +67 -0
  50. package/node_modules/@noble/hashes/src/_md.ts +227 -0
  51. package/node_modules/@noble/hashes/src/_u64.ts +111 -0
  52. package/node_modules/@noble/hashes/src/argon2.ts +693 -0
  53. package/node_modules/@noble/hashes/src/blake1.ts +677 -0
  54. package/node_modules/@noble/hashes/src/blake2.ts +648 -0
  55. package/node_modules/@noble/hashes/src/blake3.ts +344 -0
  56. package/node_modules/@noble/hashes/src/eskdf.ts +265 -0
  57. package/node_modules/@noble/hashes/src/hkdf.ts +161 -0
  58. package/node_modules/@noble/hashes/src/hmac.ts +130 -0
  59. package/node_modules/@noble/hashes/src/index.ts +33 -0
  60. package/node_modules/@noble/hashes/src/legacy.ts +361 -0
  61. package/node_modules/@noble/hashes/src/pbkdf2.ts +219 -0
  62. package/node_modules/@noble/hashes/src/scrypt.ts +375 -0
  63. package/node_modules/@noble/hashes/src/sha2.ts +486 -0
  64. package/node_modules/@noble/hashes/src/sha3-addons.ts +1157 -0
  65. package/node_modules/@noble/hashes/src/sha3.ts +525 -0
  66. package/node_modules/@noble/hashes/src/utils.ts +978 -0
  67. package/node_modules/@noble/hashes/src/webcrypto.ts +283 -0
  68. package/node_modules/@noble/hashes/utils.d.ts +560 -0
  69. package/node_modules/@noble/hashes/utils.js +687 -0
  70. package/node_modules/@noble/hashes/webcrypto.d.ts +121 -0
  71. package/node_modules/@noble/hashes/webcrypto.js +228 -0
  72. package/node_modules/@poe-code/agent-mcp-config/dist/apply.js +23 -9
  73. package/node_modules/@poe-code/config-mutations/README.md +2 -0
  74. package/node_modules/@poe-code/config-mutations/dist/execution/apply-mutation.js +4 -5
  75. package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.d.ts +3 -4
  76. package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.js +3 -3
  77. package/node_modules/@poe-code/config-mutations/dist/template/render.js +1 -1
  78. package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.d.ts +2 -2
  79. package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.js +3 -6
  80. package/node_modules/@poe-code/config-mutations/dist/types.d.ts +4 -2
  81. package/node_modules/@poe-code/process-runner/README.md +2 -1
  82. package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.d.ts +1 -0
  83. package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.js +1 -0
  84. package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.workerd.d.ts +2 -0
  85. package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.workerd.js +1 -0
  86. package/node_modules/@poe-code/process-runner/dist/types.d.ts +1 -1
  87. package/node_modules/@poe-code/process-runner/dist/workspace-transfer.d.ts +6 -5
  88. package/node_modules/@poe-code/process-runner/dist/workspace-transfer.js +67 -29
  89. package/node_modules/@poe-code/process-runner/package.json +13 -0
  90. package/node_modules/@poe-code/safe-fs/LICENSE +21 -0
  91. package/node_modules/@poe-code/safe-fs/PROVENANCE.json +428 -0
  92. package/node_modules/@poe-code/safe-fs/README.md +411 -0
  93. package/node_modules/@poe-code/safe-fs/dist/bridge/confinement.d.ts +3 -0
  94. package/node_modules/@poe-code/safe-fs/dist/bridge/confinement.js +171 -0
  95. package/node_modules/@poe-code/safe-fs/dist/bridge/filesystem.d.ts +93 -0
  96. package/node_modules/@poe-code/safe-fs/dist/bridge/filesystem.js +453 -0
  97. package/node_modules/@poe-code/safe-fs/dist/bridge/index.d.ts +7 -0
  98. package/node_modules/@poe-code/safe-fs/dist/bridge/index.js +19 -0
  99. package/node_modules/@poe-code/safe-fs/dist/bridge/stats.d.ts +4 -0
  100. package/node_modules/@poe-code/safe-fs/dist/bridge/stats.js +37 -0
  101. package/node_modules/@poe-code/safe-fs/dist/bridge/types.d.ts +81 -0
  102. package/node_modules/@poe-code/safe-fs/dist/bridge/types.js +1 -0
  103. package/node_modules/@poe-code/safe-fs/dist/bridge/values.d.ts +6 -0
  104. package/node_modules/@poe-code/safe-fs/dist/bridge/values.js +65 -0
  105. package/node_modules/@poe-code/safe-fs/dist/config/memory.d.ts +3 -0
  106. package/node_modules/@poe-code/safe-fs/dist/config/memory.js +7 -0
  107. package/node_modules/@poe-code/safe-fs/dist/config/real.d.ts +5 -0
  108. package/node_modules/@poe-code/safe-fs/dist/config/real.js +16 -0
  109. package/node_modules/@poe-code/safe-fs/dist/config/registry.d.ts +2 -0
  110. package/node_modules/@poe-code/safe-fs/dist/config/registry.js +15 -0
  111. package/node_modules/@poe-code/safe-fs/dist/config.d.ts +15 -0
  112. package/node_modules/@poe-code/safe-fs/dist/config.js +46 -0
  113. package/node_modules/@poe-code/safe-fs/dist/config.node.d.ts +2 -0
  114. package/node_modules/@poe-code/safe-fs/dist/config.node.js +11 -0
  115. package/node_modules/@poe-code/safe-fs/dist/config.portable.d.ts +3 -0
  116. package/node_modules/@poe-code/safe-fs/dist/config.portable.js +9 -0
  117. package/node_modules/@poe-code/safe-fs/dist/contracts/abort.d.ts +5 -0
  118. package/node_modules/@poe-code/safe-fs/dist/contracts/abort.js +34 -0
  119. package/node_modules/@poe-code/safe-fs/dist/contracts/cleanup.d.ts +1 -0
  120. package/node_modules/@poe-code/safe-fs/dist/contracts/cleanup.js +9 -0
  121. package/node_modules/@poe-code/safe-fs/dist/contracts/descriptor.d.ts +38 -0
  122. package/node_modules/@poe-code/safe-fs/dist/contracts/descriptor.js +1 -0
  123. package/node_modules/@poe-code/safe-fs/dist/contracts/errors.d.ts +53 -0
  124. package/node_modules/@poe-code/safe-fs/dist/contracts/errors.js +99 -0
  125. package/node_modules/@poe-code/safe-fs/dist/contracts/filesystem.d.ts +379 -0
  126. package/node_modules/@poe-code/safe-fs/dist/contracts/filesystem.js +1 -0
  127. package/node_modules/@poe-code/safe-fs/dist/contracts/index.d.ts +6 -0
  128. package/node_modules/@poe-code/safe-fs/dist/contracts/index.js +6 -0
  129. package/node_modules/@poe-code/safe-fs/dist/contracts/io.d.ts +12 -0
  130. package/node_modules/@poe-code/safe-fs/dist/contracts/io.js +321 -0
  131. package/node_modules/@poe-code/safe-fs/dist/contracts/object.d.ts +134 -0
  132. package/node_modules/@poe-code/safe-fs/dist/contracts/object.js +97 -0
  133. package/node_modules/@poe-code/safe-fs/dist/contracts/path.d.ts +3 -0
  134. package/node_modules/@poe-code/safe-fs/dist/contracts/path.js +2 -0
  135. package/node_modules/@poe-code/safe-fs/dist/contracts/portable-path.d.ts +21 -0
  136. package/node_modules/@poe-code/safe-fs/dist/contracts/portable-path.js +78 -0
  137. package/node_modules/@poe-code/safe-fs/dist/contracts/virtual-path.d.ts +15 -0
  138. package/node_modules/@poe-code/safe-fs/dist/contracts/virtual-path.js +162 -0
  139. package/node_modules/@poe-code/safe-fs/dist/core.d.ts +19 -0
  140. package/node_modules/@poe-code/safe-fs/dist/core.js +17 -0
  141. package/node_modules/@poe-code/safe-fs/dist/fs/capabilities.d.ts +10 -0
  142. package/node_modules/@poe-code/safe-fs/dist/fs/capabilities.js +216 -0
  143. package/node_modules/@poe-code/safe-fs/dist/fs/conditional-chmod.d.ts +7 -0
  144. package/node_modules/@poe-code/safe-fs/dist/fs/conditional-chmod.js +19 -0
  145. package/node_modules/@poe-code/safe-fs/dist/fs/descriptor.d.ts +21 -0
  146. package/node_modules/@poe-code/safe-fs/dist/fs/descriptor.js +279 -0
  147. package/node_modules/@poe-code/safe-fs/dist/fs/devices/index.d.ts +59 -0
  148. package/node_modules/@poe-code/safe-fs/dist/fs/devices/index.js +875 -0
  149. package/node_modules/@poe-code/safe-fs/dist/fs/devices/path.d.ts +7 -0
  150. package/node_modules/@poe-code/safe-fs/dist/fs/devices/path.js +250 -0
  151. package/node_modules/@poe-code/safe-fs/dist/fs/devices/stream.d.ts +6 -0
  152. package/node_modules/@poe-code/safe-fs/dist/fs/devices/stream.js +136 -0
  153. package/node_modules/@poe-code/safe-fs/dist/fs/directory-admission.d.ts +3 -0
  154. package/node_modules/@poe-code/safe-fs/dist/fs/directory-admission.js +14 -0
  155. package/node_modules/@poe-code/safe-fs/dist/fs/memory/atomic-view.d.ts +11 -0
  156. package/node_modules/@poe-code/safe-fs/dist/fs/memory/atomic-view.js +13 -0
  157. package/node_modules/@poe-code/safe-fs/dist/fs/memory/index.d.ts +186 -0
  158. package/node_modules/@poe-code/safe-fs/dist/fs/memory/index.js +3771 -0
  159. package/node_modules/@poe-code/safe-fs/dist/fs/memory/ledger.d.ts +26 -0
  160. package/node_modules/@poe-code/safe-fs/dist/fs/memory/ledger.js +96 -0
  161. package/node_modules/@poe-code/safe-fs/dist/fs/memory/limits.d.ts +13 -0
  162. package/node_modules/@poe-code/safe-fs/dist/fs/memory/limits.js +26 -0
  163. package/node_modules/@poe-code/safe-fs/dist/fs/memory/missing-target.d.ts +15 -0
  164. package/node_modules/@poe-code/safe-fs/dist/fs/memory/missing-target.js +144 -0
  165. package/node_modules/@poe-code/safe-fs/dist/fs/mount/comparison.d.ts +19 -0
  166. package/node_modules/@poe-code/safe-fs/dist/fs/mount/comparison.js +118 -0
  167. package/node_modules/@poe-code/safe-fs/dist/fs/mount/identity.d.ts +6 -0
  168. package/node_modules/@poe-code/safe-fs/dist/fs/mount/identity.js +29 -0
  169. package/node_modules/@poe-code/safe-fs/dist/fs/mount/index.d.ts +74 -0
  170. package/node_modules/@poe-code/safe-fs/dist/fs/mount/index.js +1291 -0
  171. package/node_modules/@poe-code/safe-fs/dist/fs/object-authority.d.ts +27 -0
  172. package/node_modules/@poe-code/safe-fs/dist/fs/object-authority.js +287 -0
  173. package/node_modules/@poe-code/safe-fs/dist/fs/object-publication/index.d.ts +45 -0
  174. package/node_modules/@poe-code/safe-fs/dist/fs/object-publication/index.js +531 -0
  175. package/node_modules/@poe-code/safe-fs/dist/fs/overlay/index.d.ts +87 -0
  176. package/node_modules/@poe-code/safe-fs/dist/fs/overlay/index.js +1185 -0
  177. package/node_modules/@poe-code/safe-fs/dist/fs/overlay/memory-publication.d.ts +42 -0
  178. package/node_modules/@poe-code/safe-fs/dist/fs/overlay/memory-publication.js +558 -0
  179. package/node_modules/@poe-code/safe-fs/dist/fs/path-namespace.d.ts +4 -0
  180. package/node_modules/@poe-code/safe-fs/dist/fs/path-namespace.js +63 -0
  181. package/node_modules/@poe-code/safe-fs/dist/fs/quota/index.d.ts +12 -0
  182. package/node_modules/@poe-code/safe-fs/dist/fs/quota/index.js +520 -0
  183. package/node_modules/@poe-code/safe-fs/dist/fs/readonly/index.d.ts +37 -0
  184. package/node_modules/@poe-code/safe-fs/dist/fs/readonly/index.js +208 -0
  185. package/node_modules/@poe-code/safe-fs/dist/fs/real/allocation.d.ts +1 -0
  186. package/node_modules/@poe-code/safe-fs/dist/fs/real/allocation.js +8 -0
  187. package/node_modules/@poe-code/safe-fs/dist/fs/real/index.d.ts +105 -0
  188. package/node_modules/@poe-code/safe-fs/dist/fs/real/index.js +1259 -0
  189. package/node_modules/@poe-code/safe-fs/dist/fs/s3/authority.d.ts +7 -0
  190. package/node_modules/@poe-code/safe-fs/dist/fs/s3/authority.js +38 -0
  191. package/node_modules/@poe-code/safe-fs/dist/fs/s3/filesystem.d.ts +130 -0
  192. package/node_modules/@poe-code/safe-fs/dist/fs/s3/filesystem.js +1137 -0
  193. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/bytes.d.ts +1 -0
  194. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/bytes.js +9 -0
  195. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/index.d.ts +2 -0
  196. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/index.js +1 -0
  197. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-fetch.d.ts +15 -0
  198. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-fetch.js +74 -0
  199. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-node.d.ts +4 -0
  200. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-node.js +111 -0
  201. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request.d.ts +17 -0
  202. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request.js +89 -0
  203. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/signature.d.ts +20 -0
  204. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/signature.js +76 -0
  205. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/transport.d.ts +3 -0
  206. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/transport.js +478 -0
  207. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/types.d.ts +30 -0
  208. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/types.js +1 -0
  209. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/xml.d.ts +14 -0
  210. package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/xml.js +192 -0
  211. package/node_modules/@poe-code/safe-fs/dist/fs/s3/index.d.ts +8 -0
  212. package/node_modules/@poe-code/safe-fs/dist/fs/s3/index.js +4 -0
  213. package/node_modules/@poe-code/safe-fs/dist/fs/s3/key-order.d.ts +2 -0
  214. package/node_modules/@poe-code/safe-fs/dist/fs/s3/key-order.js +11 -0
  215. package/node_modules/@poe-code/safe-fs/dist/fs/s3/manifest-admission.d.ts +8 -0
  216. package/node_modules/@poe-code/safe-fs/dist/fs/s3/manifest-admission.js +167 -0
  217. package/node_modules/@poe-code/safe-fs/dist/fs/s3/mock.d.ts +48 -0
  218. package/node_modules/@poe-code/safe-fs/dist/fs/s3/mock.js +249 -0
  219. package/node_modules/@poe-code/safe-fs/dist/fs/s3/namespace.d.ts +13 -0
  220. package/node_modules/@poe-code/safe-fs/dist/fs/s3/namespace.js +400 -0
  221. package/node_modules/@poe-code/safe-fs/dist/fs/s3/registry.d.ts +10 -0
  222. package/node_modules/@poe-code/safe-fs/dist/fs/s3/registry.js +73 -0
  223. package/node_modules/@poe-code/safe-fs/dist/fs/s3/transport.d.ts +103 -0
  224. package/node_modules/@poe-code/safe-fs/dist/fs/s3/transport.js +28 -0
  225. package/node_modules/@poe-code/safe-fs/dist/fs/scoped.d.ts +19 -0
  226. package/node_modules/@poe-code/safe-fs/dist/fs/scoped.js +663 -0
  227. package/node_modules/@poe-code/safe-fs/dist/fs/staging-ancestry.d.ts +8 -0
  228. package/node_modules/@poe-code/safe-fs/dist/fs/staging-ancestry.js +115 -0
  229. package/node_modules/@poe-code/safe-fs/dist/fs/staging-cleanup.d.ts +5 -0
  230. package/node_modules/@poe-code/safe-fs/dist/fs/staging-cleanup.js +63 -0
  231. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/index.d.ts +2 -0
  232. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/index.js +1 -0
  233. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/resource-id.d.ts +18 -0
  234. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/resource-id.js +109 -0
  235. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/webdav.d.ts +141 -0
  236. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/webdav.js +1377 -0
  237. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/xml.d.ts +15 -0
  238. package/node_modules/@poe-code/safe-fs/dist/fs/webdav/xml.js +59 -0
  239. package/node_modules/@poe-code/safe-fs/dist/index.d.ts +25 -0
  240. package/node_modules/@poe-code/safe-fs/dist/index.js +21 -0
  241. package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/linux-x64-glibc.node +0 -0
  242. package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/loader.d.ts +5 -0
  243. package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/loader.mjs +120 -0
  244. package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/manifest.json +46 -0
  245. package/node_modules/@poe-code/safe-fs/dist/node/filesystem.d.ts +19 -0
  246. package/node_modules/@poe-code/safe-fs/dist/node/filesystem.js +30 -0
  247. package/node_modules/@poe-code/safe-fs/dist/node/host.d.ts +3 -0
  248. package/node_modules/@poe-code/safe-fs/dist/node/host.js +78 -0
  249. package/node_modules/@poe-code/safe-fs/dist/node/index.d.ts +3 -0
  250. package/node_modules/@poe-code/safe-fs/dist/node/index.js +2 -0
  251. package/node_modules/@poe-code/safe-fs/dist/node/native-seek-unavailable.d.ts +1 -0
  252. package/node_modules/@poe-code/safe-fs/dist/node/native-seek-unavailable.js +5 -0
  253. package/node_modules/@poe-code/safe-fs/dist/node/native-seek.d.ts +3 -0
  254. package/node_modules/@poe-code/safe-fs/dist/node/native-seek.js +54 -0
  255. package/node_modules/@poe-code/safe-fs/dist/node/stats.d.ts +1 -0
  256. package/node_modules/@poe-code/safe-fs/dist/node/stats.js +1 -0
  257. package/node_modules/@poe-code/safe-fs/dist/node/values.d.ts +1 -0
  258. package/node_modules/@poe-code/safe-fs/dist/node/values.js +1 -0
  259. package/node_modules/@poe-code/safe-fs/dist/node-host.d.ts +1 -0
  260. package/node_modules/@poe-code/safe-fs/dist/node-host.js +1 -0
  261. package/node_modules/@poe-code/safe-fs/dist/node-unavailable.d.ts +1 -0
  262. package/node_modules/@poe-code/safe-fs/dist/node-unavailable.js +1 -0
  263. package/node_modules/@poe-code/safe-fs/dist/package.json +29 -0
  264. package/node_modules/@poe-code/safe-fs/dist/platform/browser-path.d.ts +1 -0
  265. package/node_modules/@poe-code/safe-fs/dist/platform/browser-path.js +1 -0
  266. package/node_modules/@poe-code/safe-fs/dist/platform/browser.d.ts +26 -0
  267. package/node_modules/@poe-code/safe-fs/dist/platform/browser.js +58 -0
  268. package/node_modules/@poe-code/safe-fs/dist/platform/node-path.d.ts +1 -0
  269. package/node_modules/@poe-code/safe-fs/dist/platform/node-path.js +1 -0
  270. package/node_modules/@poe-code/safe-fs/dist/platform/node.d.ts +26 -0
  271. package/node_modules/@poe-code/safe-fs/dist/platform/node.js +64 -0
  272. package/node_modules/@poe-code/safe-fs/dist/platform/transport-budget.d.ts +9 -0
  273. package/node_modules/@poe-code/safe-fs/dist/platform/transport-budget.js +17 -0
  274. package/node_modules/@poe-code/safe-fs/dist/python/emscripten.d.ts +15 -0
  275. package/node_modules/@poe-code/safe-fs/dist/python/emscripten.js +357 -0
  276. package/node_modules/@poe-code/safe-fs/dist/python/filesystem.d.ts +51 -0
  277. package/node_modules/@poe-code/safe-fs/dist/python/filesystem.js +243 -0
  278. package/node_modules/@poe-code/safe-fs/dist/python/flags.d.ts +3 -0
  279. package/node_modules/@poe-code/safe-fs/dist/python/flags.js +14 -0
  280. package/node_modules/@poe-code/safe-fs/dist/python/index.d.ts +9 -0
  281. package/node_modules/@poe-code/safe-fs/dist/python/index.js +5 -0
  282. package/node_modules/@poe-code/safe-fs/dist/python/native.d.ts +18 -0
  283. package/node_modules/@poe-code/safe-fs/dist/python/native.js +446 -0
  284. package/node_modules/@poe-code/safe-fs/dist/python/request.d.ts +2 -0
  285. package/node_modules/@poe-code/safe-fs/dist/python/request.js +61 -0
  286. package/node_modules/@poe-code/safe-fs/dist/python/stat.d.ts +8 -0
  287. package/node_modules/@poe-code/safe-fs/dist/python/stat.js +34 -0
  288. package/node_modules/@poe-code/safe-fs/dist/runtime-core.d.ts +27 -0
  289. package/node_modules/@poe-code/safe-fs/dist/runtime-core.js +57 -0
  290. package/node_modules/@poe-code/safe-fs/dist/testing/atomic-filesystem.d.ts +16 -0
  291. package/node_modules/@poe-code/safe-fs/dist/testing/atomic-filesystem.js +496 -0
  292. package/node_modules/@poe-code/safe-fs/dist/testing/object-io-control.d.ts +23 -0
  293. package/node_modules/@poe-code/safe-fs/dist/testing/object-io-control.js +39 -0
  294. package/node_modules/@poe-code/safe-fs/dist/testing/object-io-metrics.d.ts +31 -0
  295. package/node_modules/@poe-code/safe-fs/dist/testing/object-io-metrics.js +143 -0
  296. package/node_modules/@poe-code/safe-fs/dist/testing/object-publication.d.ts +19 -0
  297. package/node_modules/@poe-code/safe-fs/dist/testing/object-publication.js +209 -0
  298. package/node_modules/@poe-code/safe-fs/dist/xml.d.ts +1 -0
  299. package/node_modules/@poe-code/safe-fs/dist/xml.js +1 -0
  300. package/node_modules/@poe-code/safe-fs/package.json +189 -0
  301. package/node_modules/@poe-code/task-list/README.md +2 -0
  302. package/node_modules/@poe-code/task-list/dist/backends/gh-issues-client.d.ts +1 -1
  303. package/node_modules/@poe-code/task-list/dist/backends/gh-issues-client.js +11 -4
  304. package/node_modules/@poe-code/task-list/dist/backends/markdown-dir.js +2 -2
  305. package/node_modules/@poe-code/task-list/dist/backends/utils.js +5 -7
  306. package/node_modules/@poe-code/task-list/dist/backends/yaml-file.js +1 -1
  307. package/node_modules/@poe-code/task-list/dist/default-host.d.ts +2 -0
  308. package/node_modules/@poe-code/task-list/dist/default-host.js +2 -0
  309. package/node_modules/@poe-code/task-list/dist/default-host.workerd.d.ts +4 -0
  310. package/node_modules/@poe-code/task-list/dist/default-host.workerd.js +6 -0
  311. package/node_modules/@poe-code/task-list/dist/filesystem.d.ts +3 -0
  312. package/node_modules/@poe-code/task-list/dist/filesystem.js +32 -0
  313. package/node_modules/@poe-code/task-list/dist/move.js +3 -3
  314. package/node_modules/@poe-code/task-list/dist/open.js +2 -5
  315. package/node_modules/@poe-code/task-list/dist/paths.d.ts +12 -0
  316. package/node_modules/@poe-code/task-list/dist/paths.js +7 -0
  317. package/node_modules/@poe-code/task-list/dist/types.d.ts +6 -5
  318. package/node_modules/@poe-code/task-list/package.json +9 -0
  319. package/node_modules/@poe-code/terminal-text/LICENSE +21 -0
  320. package/node_modules/@poe-code/terminal-text/README.md +12 -0
  321. package/node_modules/@poe-code/terminal-text/dist/index.d.ts +2 -0
  322. package/node_modules/@poe-code/terminal-text/dist/index.js +20 -0
  323. package/node_modules/@poe-code/terminal-text/package.json +22 -0
  324. package/node_modules/@poe-code/xml-ast/LICENSE +21 -0
  325. package/node_modules/@poe-code/xml-ast/README.md +28 -0
  326. package/node_modules/@poe-code/xml-ast/dist/index.d.ts +47 -0
  327. package/node_modules/@poe-code/xml-ast/dist/index.js +635 -0
  328. package/node_modules/@poe-code/xml-ast/package.json +25 -0
  329. package/node_modules/auth-store/README.md +35 -0
  330. package/node_modules/auth-store/dist/index.browser.d.ts +4 -0
  331. package/node_modules/auth-store/dist/index.browser.js +2 -0
  332. package/node_modules/auth-store/dist/provider-store.d.ts +1 -1
  333. package/node_modules/auth-store/dist/safe-fs-secret-store.d.ts +21 -0
  334. package/node_modules/auth-store/dist/safe-fs-secret-store.js +119 -0
  335. package/node_modules/auth-store/dist/secret-store.d.ts +12 -0
  336. package/node_modules/auth-store/dist/secret-store.js +1 -0
  337. package/node_modules/auth-store/dist/transaction-lock.d.ts +2 -4
  338. package/node_modules/auth-store/dist/types.d.ts +2 -9
  339. package/node_modules/auth-store/package.json +16 -2
  340. package/node_modules/tiny-http-mcp-server/dist/composition.json +16 -1
  341. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/README.md +25 -0
  342. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/authorization-state.js +4 -4
  343. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.js +6 -40
  344. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/oauth-form.d.ts +10 -0
  345. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/oauth-form.js +20 -0
  346. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/pkce.js +4 -3
  347. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/register-client.d.ts +14 -0
  348. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/register-client.js +53 -0
  349. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/resumable.d.ts +16 -2
  350. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/resumable.js +29 -9
  351. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/revoke-token.d.ts +12 -0
  352. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/revoke-token.js +23 -0
  353. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.js +6 -19
  354. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/http-fetch.js +1 -1
  355. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.browser.d.ts +6 -2
  356. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.browser.js +5 -1
  357. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.d.ts +5 -2
  358. package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.js +4 -1
  359. package/node_modules/tiny-http-mcp-server/package.json +4 -4
  360. package/node_modules/tiny-mcp-client/README.md +2 -0
  361. package/node_modules/tiny-mcp-client/dist/index.browser.d.ts +25 -23
  362. package/node_modules/tiny-mcp-client/dist/index.browser.js +116 -1
  363. package/node_modules/tiny-mcp-client/dist/index.d.ts +25 -23
  364. package/node_modules/tiny-mcp-client/dist/index.js +1034 -561
  365. package/node_modules/tiny-mcp-client/package.json +15 -0
  366. package/node_modules/tiny-stdio-mcp-server/dist/composition.json +1 -1
  367. package/node_modules/toolcraft-design/dist/components/table.js +6 -0
  368. package/node_modules/toolcraft-design/dist/escape-terminal-text.d.ts +1 -2
  369. package/node_modules/toolcraft-design/dist/escape-terminal-text.js +1 -20
  370. package/node_modules/toolcraft-design/dist/terminal-markdown/parser/frontmatter.js +2 -1
  371. package/node_modules/toolcraft-design/dist/terminal-markdown/parser.js +2 -1
  372. package/node_modules/toolcraft-schema/dist/json-schema/utils.js +3 -0
  373. package/node_modules/toolcraft-schema/package.json +1 -1
  374. package/package.json +32 -7
@@ -0,0 +1,219 @@
1
+ /**
2
+ * PBKDF (RFC 2898). Can be used to create a key from password and salt.
3
+ * @module
4
+ */
5
+ import { hmac } from './hmac.ts';
6
+ // prettier-ignore
7
+ import {
8
+ ahash, anumber,
9
+ asyncLoop, checkOpts, clean, createView, kdfInputToBytes,
10
+ type CHash,
11
+ type Hash,
12
+ type KDFInput,
13
+ type TArg,
14
+ type TRet
15
+ } from './utils.ts';
16
+
17
+ /**
18
+ * PBKDF2 options:
19
+ * * c: iterations, should probably be higher than 100_000
20
+ * * dkLen: desired length of derived key in bytes, must be `>= 1` per RFC 8018 §5.2
21
+ * * asyncTick: max time in ms for which async function can block execution
22
+ */
23
+ export type Pbkdf2Opt = {
24
+ /** Iteration count. Higher values increase CPU cost. */
25
+ c: number;
26
+ /** Desired derived key length in bytes, must be `>= 1` per RFC 8018 §5.2. */
27
+ dkLen?: number;
28
+ /** Max scheduler block time in milliseconds for the async variant. */
29
+ asyncTick?: number;
30
+ };
31
+ // Common validation and per-call state setup for sync/async functions.
32
+ function pbkdf2Init(
33
+ hash: TArg<CHash>,
34
+ _password: TArg<KDFInput>,
35
+ _salt: TArg<KDFInput>,
36
+ _opts: Pbkdf2Opt
37
+ ) {
38
+ ahash(hash);
39
+ const opts = checkOpts({ dkLen: 32, asyncTick: 10 }, _opts);
40
+ const { c, dkLen, asyncTick } = opts;
41
+ anumber(c, 'c');
42
+ anumber(dkLen, 'dkLen');
43
+ anumber(asyncTick, 'asyncTick');
44
+ if (c < 1) throw new Error('"c" (iterations) must be >= 1');
45
+ // RFC 8018 §5.2 defines `dkLen` as "a positive integer".
46
+ if (dkLen < 1) throw new Error('"dkLen" must be >= 1');
47
+ // RFC 8018 §5.2 step 1 requires rejecting oversize `dkLen`
48
+ // before allocating the destination buffer.
49
+ if (dkLen > (2 ** 32 - 1) * hash.outputLen) throw new Error('derived key too long');
50
+ const p = kdfInputToBytes(_password, 'password');
51
+ try {
52
+ const s = kdfInputToBytes(_salt, 'salt');
53
+ try {
54
+ // DK = PBKDF2(PRF, Password, Salt, c, dkLen);
55
+ const DK = new Uint8Array(dkLen);
56
+ const { iHash, oHash, outputLen } = hmac.create(hash, p);
57
+ // Drive keyed hashes directly; the wrapper is only needed to initialize their HMAC midstates.
58
+ const u = new Uint8Array(outputLen);
59
+ const eng = pbkdf2Engine(iHash, oHash, s, u);
60
+ return { c, dkLen, asyncTick, DK, outputLen, eng };
61
+ } finally {
62
+ // Uint8Array inputs belong to the caller; only wipe our UTF-8 conversion.
63
+ if (typeof _salt === 'string') clean(s);
64
+ }
65
+ } finally {
66
+ if (typeof _password === 'string') clean(p);
67
+ }
68
+ }
69
+
70
+ // Per-call PRF driver writes U1 into both `u` and `Ti`, then later digests into `u`;
71
+ // shared by the sync and async variants.
72
+ function pbkdf2Engine(
73
+ iHash: TArg<Hash<any>>,
74
+ oHash: TArg<Hash<any>>,
75
+ salt: TArg<Uint8Array>,
76
+ u: TArg<Uint8Array>
77
+ ) {
78
+ const counter = new Uint8Array(4);
79
+ const view = createView(counter);
80
+ // Full clones retain tree/config state; absorb salt before async yields without cloning input.
81
+ const salted = iHash._cloneInto().update(salt);
82
+ // u1() overwrites the worker before reading it. Seed from the outer midstate so a long salt
83
+ // cannot pre-populate a tree stack that the first reset would abandon without wiping.
84
+ const work = oHash._cloneInto();
85
+ const iClone = iHash._cloneInto; // Capture before mixed feedback can materialize state tuples.
86
+ const oClone = oHash._cloneInto;
87
+ return {
88
+ u1: (ti: number, Ti: TArg<Uint8Array>) => {
89
+ view.setInt32(0, ti, false);
90
+ salted._cloneInto(work).update(counter).digestInto(u);
91
+ oHash._cloneInto(work).update(u).digestInto(u);
92
+ Ti.set(u.subarray(0, Ti.length));
93
+ },
94
+ // Whole `F` inner loop for the sync variant: one optimized function owns the hot loop.
95
+ rounds: (c: number, Ti: TArg<Uint8Array>) => {
96
+ for (let ui = 1; ui < c; ui++) {
97
+ iClone.call(iHash, work).update(u).digestInto(u);
98
+ oClone.call(oHash, work).update(u).digestInto(u);
99
+ for (let i = 0; i < Ti.length; i++) Ti[i] ^= u[i];
100
+ }
101
+ },
102
+ output: (DK: TArg<Uint8Array>): TRet<Uint8Array> => {
103
+ // Keyed templates and derived worker states are secret material.
104
+ iHash.destroy();
105
+ oHash.destroy();
106
+ salted.destroy();
107
+ work.destroy();
108
+ // Shared sync/async cleanup point: wipe transient PRF state
109
+ // while preserving the derived key buffer.
110
+ clean(u);
111
+ return DK as TRet<Uint8Array>;
112
+ },
113
+ };
114
+ }
115
+
116
+ /**
117
+ * PBKDF2-HMAC: RFC 8018 key derivation function.
118
+ * @param hash - hash function that would be used e.g. sha256
119
+ * @param password - password from which a derived key is generated;
120
+ * JS string inputs are UTF-8 encoded first
121
+ * @param salt - cryptographic salt; JS string inputs are UTF-8 encoded first
122
+ * @param opts - PBKDF2 work factor and output settings. `dkLen`, if provided,
123
+ * must be `>= 1` per RFC 8018 §5.2. See {@link Pbkdf2Opt}.
124
+ * @returns Derived key bytes.
125
+ * @throws If the PBKDF2 iteration count or derived-key settings are invalid. {@link Error}
126
+ * @example
127
+ * PBKDF2-HMAC: RFC 2898 key derivation function.
128
+ * ```ts
129
+ * import { pbkdf2 } from '@noble/hashes/pbkdf2.js';
130
+ * import { sha256 } from '@noble/hashes/sha2.js';
131
+ * const key = pbkdf2(sha256, 'password', 'salt', { dkLen: 32, c: Math.pow(2, 18) });
132
+ * ```
133
+ */
134
+ export function pbkdf2(
135
+ hash: TArg<CHash>,
136
+ password: TArg<KDFInput>,
137
+ salt: TArg<KDFInput>,
138
+ opts: Pbkdf2Opt
139
+ ): TRet<Uint8Array> {
140
+ const { c, dkLen, DK, outputLen, eng } = pbkdf2Init(hash, password, salt, opts);
141
+ // DK = T1 + T2 + ⋯ + Tdklen/hlen
142
+ for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += outputLen) {
143
+ // Ti = F(Password, Salt, c, i)
144
+ // The last Ti view can be shorter than hLen, which applies
145
+ // RFC 8018 §5.2 step 4's T_l<0..r-1> truncation without extra copies.
146
+ const Ti = DK.subarray(pos, pos + outputLen);
147
+ // F(Password, Salt, c, i) = U1 ^ U2 ^ ⋯ ^ Uc
148
+ // U1 = PRF(Password, Salt + INT_32_BE(i))
149
+ eng.u1(ti, Ti);
150
+ // Uc = PRF(Password, Uc−1); Ti ^= Uc
151
+ eng.rounds(c, Ti);
152
+ }
153
+ return eng.output(DK);
154
+ }
155
+
156
+ /**
157
+ * PBKDF2-HMAC: RFC 8018 key derivation function. Async version.
158
+ * @param hash - hash function that would be used e.g. sha256
159
+ * @param password - password from which a derived key is generated;
160
+ * JS string inputs are UTF-8 encoded first
161
+ * @param salt - cryptographic salt; JS string inputs are UTF-8 encoded first
162
+ * @param opts - PBKDF2 work factor and output settings. `dkLen`, if provided,
163
+ * must be `>= 1` per RFC 8018 §5.2. `asyncTick` is only a local
164
+ * scheduler-yield knob for this JS wrapper, not part of RFC 8018.
165
+ * See {@link Pbkdf2Opt}.
166
+ * @returns Promise resolving to derived key bytes.
167
+ * @throws If the PBKDF2 iteration count or derived-key settings are invalid. {@link Error}
168
+ * @example
169
+ * PBKDF2-HMAC: RFC 2898 key derivation function.
170
+ * ```ts
171
+ * import { pbkdf2Async } from '@noble/hashes/pbkdf2.js';
172
+ * import { sha256 } from '@noble/hashes/sha2.js';
173
+ * const key = await pbkdf2Async(sha256, 'password', 'salt', { dkLen: 32, c: 500_000 });
174
+ * ```
175
+ * @example
176
+ * Tune the async PBKDF2 scheduler for short UI tasks.
177
+ * ```ts
178
+ * import { pbkdf2Async } from '@noble/hashes/pbkdf2.js';
179
+ * import { sha256 } from '@noble/hashes/sha2.js';
180
+ * const key = await pbkdf2Async(sha256, 'password', 'salt', {
181
+ * dkLen: 32,
182
+ * c: 32,
183
+ * asyncTick: 1,
184
+ * });
185
+ * ```
186
+ */
187
+ export async function pbkdf2Async(
188
+ hash: TArg<CHash>,
189
+ password: TArg<KDFInput>,
190
+ salt: TArg<KDFInput>,
191
+ opts: Pbkdf2Opt
192
+ ): Promise<TRet<Uint8Array>> {
193
+ const { c, dkLen, asyncTick, DK, outputLen, eng } = pbkdf2Init(hash, password, salt, opts);
194
+ // Reuse normal state destruction, then wipe the incomplete output if a host yield aborts.
195
+ const abort = () => {
196
+ eng.output(DK);
197
+ clean(DK);
198
+ };
199
+ // DK = T1 + T2 + ⋯ + Tdklen/hlen
200
+ for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += outputLen) {
201
+ // Ti = F(Password, Salt, c, i)
202
+ // The last Ti view can be shorter than hLen, which applies
203
+ // RFC 8018 §5.2 step 4's T_l<0..r-1> truncation without extra copies.
204
+ const Ti = DK.subarray(pos, pos + outputLen);
205
+ // F(Password, Salt, c, i) = U1 ^ U2 ^ ⋯ ^ Uc
206
+ // U1 = PRF(Password, Salt + INT_32_BE(i))
207
+ eng.u1(ti, Ti);
208
+ await asyncLoop(
209
+ c - 1,
210
+ asyncTick,
211
+ () => {
212
+ // Uc = PRF(Password, Uc−1)
213
+ eng.rounds(2, Ti); // c=2 runs exactly one PRF iteration per callback.
214
+ },
215
+ abort
216
+ );
217
+ }
218
+ return eng.output(DK);
219
+ }
@@ -0,0 +1,375 @@
1
+ /**
2
+ * RFC 7914 Scrypt KDF. Can be used to create a key from password and salt.
3
+ * @module
4
+ */
5
+ import { pbkdf2 } from './pbkdf2.ts';
6
+ import { sha256 } from './sha2.ts';
7
+ // prettier-ignore
8
+ import {
9
+ anumber, asyncLoop,
10
+ checkOpts, clean,
11
+ rotl,
12
+ swap32IfBE,
13
+ u32,
14
+ type KDFInput,
15
+ type TArg,
16
+ type TRet
17
+ } from './utils.ts';
18
+
19
+ // The main Scrypt loop: uses Salsa extensively.
20
+ // Six versions of the function were tried, this is the fastest one.
21
+ // RFC 7914 §3 / §4 step 2 applies Salsa20/8 to one 16-word (64-byte) block
22
+ // after xor'ing two such blocks.
23
+ // The local `y*` snapshot keeps the xor input stable even when `out` aliases `prev` or `input`.
24
+ // prettier-ignore
25
+ function XorAndSalsa(
26
+ prev: TArg<Uint32Array>,
27
+ pi: number,
28
+ input: TArg<Uint32Array>,
29
+ ii: number,
30
+ out: TArg<Uint32Array>,
31
+ oi: number
32
+ ) {
33
+ // Based on https://cr.yp.to/salsa20.html and RFC 7914's Salsa20/8 core.
34
+ // Xor blocks
35
+ let y00 = prev[pi++] ^ input[ii++], y01 = prev[pi++] ^ input[ii++];
36
+ let y02 = prev[pi++] ^ input[ii++], y03 = prev[pi++] ^ input[ii++];
37
+ let y04 = prev[pi++] ^ input[ii++], y05 = prev[pi++] ^ input[ii++];
38
+ let y06 = prev[pi++] ^ input[ii++], y07 = prev[pi++] ^ input[ii++];
39
+ let y08 = prev[pi++] ^ input[ii++], y09 = prev[pi++] ^ input[ii++];
40
+ let y10 = prev[pi++] ^ input[ii++], y11 = prev[pi++] ^ input[ii++];
41
+ let y12 = prev[pi++] ^ input[ii++], y13 = prev[pi++] ^ input[ii++];
42
+ let y14 = prev[pi++] ^ input[ii++], y15 = prev[pi++] ^ input[ii++];
43
+ // Save state to temporary variables (salsa)
44
+ let x00 = y00, x01 = y01, x02 = y02, x03 = y03,
45
+ x04 = y04, x05 = y05, x06 = y06, x07 = y07,
46
+ x08 = y08, x09 = y09, x10 = y10, x11 = y11,
47
+ x12 = y12, x13 = y13, x14 = y14, x15 = y15;
48
+ // Main loop (salsa)
49
+ for (let i = 0; i < 8; i += 2) {
50
+ x04 ^= rotl(x00 + x12 | 0, 7); x08 ^= rotl(x04 + x00 | 0, 9);
51
+ x12 ^= rotl(x08 + x04 | 0, 13); x00 ^= rotl(x12 + x08 | 0, 18);
52
+ x09 ^= rotl(x05 + x01 | 0, 7); x13 ^= rotl(x09 + x05 | 0, 9);
53
+ x01 ^= rotl(x13 + x09 | 0, 13); x05 ^= rotl(x01 + x13 | 0, 18);
54
+ x14 ^= rotl(x10 + x06 | 0, 7); x02 ^= rotl(x14 + x10 | 0, 9);
55
+ x06 ^= rotl(x02 + x14 | 0, 13); x10 ^= rotl(x06 + x02 | 0, 18);
56
+ x03 ^= rotl(x15 + x11 | 0, 7); x07 ^= rotl(x03 + x15 | 0, 9);
57
+ x11 ^= rotl(x07 + x03 | 0, 13); x15 ^= rotl(x11 + x07 | 0, 18);
58
+ x01 ^= rotl(x00 + x03 | 0, 7); x02 ^= rotl(x01 + x00 | 0, 9);
59
+ x03 ^= rotl(x02 + x01 | 0, 13); x00 ^= rotl(x03 + x02 | 0, 18);
60
+ x06 ^= rotl(x05 + x04 | 0, 7); x07 ^= rotl(x06 + x05 | 0, 9);
61
+ x04 ^= rotl(x07 + x06 | 0, 13); x05 ^= rotl(x04 + x07 | 0, 18);
62
+ x11 ^= rotl(x10 + x09 | 0, 7); x08 ^= rotl(x11 + x10 | 0, 9);
63
+ x09 ^= rotl(x08 + x11 | 0, 13); x10 ^= rotl(x09 + x08 | 0, 18);
64
+ x12 ^= rotl(x15 + x14 | 0, 7); x13 ^= rotl(x12 + x15 | 0, 9);
65
+ x14 ^= rotl(x13 + x12 | 0, 13); x15 ^= rotl(x14 + x13 | 0, 18);
66
+ }
67
+ // Write output (salsa)
68
+ out[oi++] = (y00 + x00) | 0; out[oi++] = (y01 + x01) | 0;
69
+ out[oi++] = (y02 + x02) | 0; out[oi++] = (y03 + x03) | 0;
70
+ out[oi++] = (y04 + x04) | 0; out[oi++] = (y05 + x05) | 0;
71
+ out[oi++] = (y06 + x06) | 0; out[oi++] = (y07 + x07) | 0;
72
+ out[oi++] = (y08 + x08) | 0; out[oi++] = (y09 + x09) | 0;
73
+ out[oi++] = (y10 + x10) | 0; out[oi++] = (y11 + x11) | 0;
74
+ out[oi++] = (y12 + x12) | 0; out[oi++] = (y13 + x13) | 0;
75
+ out[oi++] = (y14 + x14) | 0; out[oi++] = (y15 + x15) | 0;
76
+ }
77
+
78
+ function BlockMix(
79
+ input: TArg<Uint32Array>,
80
+ ii: number,
81
+ out: TArg<Uint32Array>,
82
+ oi: number,
83
+ r: number
84
+ ) {
85
+ // The block B is `r` 128-byte chunks, i.e. `2r` 16-word (64-byte) Salsa blocks.
86
+ let head = oi + 0;
87
+ let tail = oi + 16 * r;
88
+ for (let i = 0; i < 16; i++) out[tail + i] = input[ii + (2 * r - 1) * 16 + i]; // X ← B[2r−1]
89
+ for (let i = 0; i < r; i++, head += 16, ii += 16) {
90
+ // RFC 7914 §4 step 3 outputs `Y[0], Y[2], ...` first, then `Y[1], Y[3], ...`;
91
+ // `head` and `tail` lay out those even/odd halves in place.
92
+ XorAndSalsa(out, tail, input, ii, out, head); // head[i] = Salsa(blockIn[2*i] ^ tail[i-1])
93
+ if (i > 0) tail += 16; // First iteration overwrites tmp value in tail
94
+ // tail[i] = Salsa(blockIn[2*i+1] ^ head[i])
95
+ XorAndSalsa(out, head, input, (ii += 16), out, tail);
96
+ }
97
+ }
98
+
99
+ // 128*r*(N+p+1) for N=2**20, r=8, p=1: 1 GiB main table plus 2 KiB workspace.
100
+ const SCRYPT_DEFAULT_MAXMEM = 128 * 8 * (2 ** 20 + 1 + 1);
101
+
102
+ /**
103
+ * Scrypt options:
104
+ * - `N` is cpu/mem work factor (power of 2 e.g. `2**18`)
105
+ * - `r` is block size (8 is common), fine-tunes sequential memory read size and performance
106
+ * - `p` is parallelization factor (1 is common)
107
+ * - `dkLen` is output key length in bytes e.g. 32, and must be `>= 1` per RFC 7914 §2.
108
+ * - `asyncTick` - (default: 10) max time in ms for which async function can block execution
109
+ * - `maxmem` - (default: `1024 ** 3 + 2 * 1024` aka 1GiB+2KiB). A limit that the app
110
+ * could use for scrypt
111
+ * - `onProgress` - callback function that would be executed for progress report
112
+ */
113
+ export type ScryptOpts = {
114
+ /** CPU and memory work factor. Must be a power of two. */
115
+ N: number;
116
+ /** Block size parameter. */
117
+ r: number;
118
+ /** Parallelization factor. */
119
+ p: number;
120
+ /** Desired derived key length in bytes, must be `>= 1` per RFC 7914 §2. */
121
+ dkLen?: number;
122
+ /** Max scheduler block time in milliseconds for the async variant. */
123
+ asyncTick?: number;
124
+ /** Maximum temporary memory budget in bytes. */
125
+ maxmem?: number;
126
+ /**
127
+ * Optional progress callback invoked during long-running derivations.
128
+ * @param progress - completion fraction in the `0..1` range
129
+ * Should not throw; if it does, derivation is aborted and scrypt work
130
+ * buffers are wiped before the error propagates.
131
+ */
132
+ onProgress?: (progress: number) => void;
133
+ };
134
+
135
+ // Common prologue and epilogue for sync/async functions
136
+ function scryptInit(password: TArg<KDFInput>, salt: TArg<KDFInput>, _opts?: ScryptOpts) {
137
+ const opts = checkOpts(
138
+ {
139
+ dkLen: 32,
140
+ asyncTick: 10,
141
+ maxmem: SCRYPT_DEFAULT_MAXMEM,
142
+ },
143
+ _opts
144
+ );
145
+ const { N, r, p, dkLen, asyncTick, maxmem, onProgress } = opts;
146
+ anumber(N, 'N');
147
+ anumber(r, 'r');
148
+ anumber(p, 'p');
149
+ anumber(dkLen, 'dkLen');
150
+ anumber(asyncTick, 'asyncTick');
151
+ anumber(maxmem, 'maxmem');
152
+ if (onProgress !== undefined && typeof onProgress !== 'function')
153
+ throw new Error('"onProgress" must be a function');
154
+ // Without this, r=0 slips through: blockSize=0 turns the `p` upper bound into
155
+ // Infinity and the failure surfaces later as a confusing pbkdf2 dkLen error.
156
+ if (r < 1) throw new Error('"r" expected integer >= 1');
157
+ const blockSize = 128 * r;
158
+ const blockSize32 = blockSize / 4;
159
+
160
+ // Max N is 2^32 (Integrify is 32-bit).
161
+ // Real limit can be 2^22: some JS engines limit Uint8Array to 4GB.
162
+ // Spec check `N >= 2^(blockSize / 8)` is not done for compat with popular libs,
163
+ // which used incorrect r: 1, p: 8. Also, the check seems to be a spec error:
164
+ // https://www.rfc-editor.org/errata_search.php?rfc=7914
165
+ const pow32 = Math.pow(2, 32);
166
+ if (N <= 1 || (N & (N - 1)) !== 0 || N > pow32)
167
+ throw new Error('"N" expected a power of 2, and 2^1 <= N <= 2^32');
168
+ if (p < 1 || p > ((pow32 - 1) * 32) / blockSize)
169
+ throw new Error('"p" expected integer 1..((2^32 - 1) * 32) / (128 * r)');
170
+ // RFC 7914 §2 defines `dkLen` as a positive integer.
171
+ if (dkLen < 1 || dkLen > (pow32 - 1) * 32)
172
+ throw new Error('"dkLen" expected integer 1..(2^32 - 1) * 32');
173
+ // Include the shared `tmp` scratch block so `maxmem` matches noble's actual temporary allocation.
174
+ // Node requires more headroom here, so this accounting is intentionally noble-specific.
175
+ const memUsed = blockSize * (N + p + 1);
176
+ if (memUsed > maxmem)
177
+ throw new Error(
178
+ '"maxmem" limit was hit: memUsed(128*r*(N+p+1))=' + memUsed + ', maxmem=' + maxmem
179
+ );
180
+ // [B0...Bp−1] ← PBKDF2HMAC-SHA256(Passphrase, Salt, 1, blockSize*ParallelizationFactor)
181
+ // Since it has only one iteration there is no reason to use async variant
182
+ const B = pbkdf2(sha256, password, salt, { c: 1, dkLen: blockSize * p });
183
+ const B32 = u32(B);
184
+ // Re-used between parallel iterations. Array(iterations) of B
185
+ const V = u32(new Uint8Array(blockSize * N));
186
+ const tmp = u32(new Uint8Array(blockSize));
187
+ let blockMixCb = () => {};
188
+ if (onProgress) {
189
+ const totalBlockMix = 2 * N * p;
190
+ // Invoke callback if progress changes from 10.01 to 10.02
191
+ // Allows to draw smooth progress bar on up to 8K screen
192
+ const callbackPer = Math.max(Math.floor(totalBlockMix / 10000), 1);
193
+ let blockMixCnt = 0;
194
+ blockMixCb = () => {
195
+ blockMixCnt++;
196
+ if (onProgress && (!(blockMixCnt % callbackPer) || blockMixCnt === totalBlockMix)) {
197
+ // Wiping here instead of a try/catch around the main loops keeps them
198
+ // try-free: measured ~1% slower at N=2^21 with the loops inside a try.
199
+ // onProgress is the only user code that can throw mid-derivation.
200
+ try {
201
+ onProgress(blockMixCnt / totalBlockMix);
202
+ } catch (e) {
203
+ clean(B, V, tmp);
204
+ throw e;
205
+ }
206
+ }
207
+ };
208
+ }
209
+ return { N, r, p, dkLen, blockSize32, V, B32, B, tmp, blockMixCb, asyncTick };
210
+ }
211
+
212
+ function scryptOutput(
213
+ password: TArg<KDFInput>,
214
+ dkLen: number,
215
+ B: TArg<Uint8Array>,
216
+ V: TArg<Uint32Array>,
217
+ tmp: TArg<Uint32Array>
218
+ ): TRet<Uint8Array> {
219
+ // Shared final PBKDF2-and-cleanup step: keep the derived key, wipe the scrypt workspace.
220
+ const res = pbkdf2(sha256, password, B, { c: 1, dkLen });
221
+ clean(B, V, tmp);
222
+ return res;
223
+ }
224
+
225
+ /**
226
+ * Scrypt KDF from RFC 7914. See {@link ScryptOpts}.
227
+ * @param password - password or key material to derive from;
228
+ * JS string inputs are UTF-8 encoded first
229
+ * @param salt - unique salt bytes or string; JS string inputs are UTF-8 encoded first
230
+ * @param opts - Scrypt cost and memory parameters. `dkLen`, if provided,
231
+ * must be `>= 1` per RFC 7914 §2. See {@link ScryptOpts}.
232
+ * @returns Derived key bytes.
233
+ * @throws If the Scrypt cost, memory, or callback options are invalid. {@link Error}
234
+ * @example
235
+ * Derive a key with scrypt.
236
+ * ```ts
237
+ * scrypt('password', 'salt', { N: 2**18, r: 8, p: 1, dkLen: 32 });
238
+ * ```
239
+ * @example
240
+ * Derive a key with small demo costs and progress/memory controls.
241
+ * ```ts
242
+ * const progressLog: number[] = [];
243
+ * scrypt('password', 'salt', {
244
+ * N: 16,
245
+ * r: 8,
246
+ * p: 1,
247
+ * dkLen: 32,
248
+ * maxmem: 1024 * 1024,
249
+ * asyncTick: 10,
250
+ * onProgress(progress) {
251
+ * progressLog.push(progress);
252
+ * },
253
+ * });
254
+ * ```
255
+ */
256
+ export function scrypt(
257
+ password: TArg<KDFInput>,
258
+ salt: TArg<KDFInput>,
259
+ opts: ScryptOpts
260
+ ): TRet<Uint8Array> {
261
+ const { N, r, p, dkLen, blockSize32, V, B32, B, tmp, blockMixCb } = scryptInit(
262
+ password,
263
+ salt,
264
+ opts
265
+ );
266
+ swap32IfBE(B32);
267
+ for (let pi = 0; pi < p; pi++) {
268
+ const Pi = blockSize32 * pi;
269
+ for (let i = 0; i < blockSize32; i++) V[i] = B32[Pi + i]; // V[0] = B[i]
270
+ for (let i = 0, pos = 0; i < N - 1; i++) {
271
+ BlockMix(V, pos, V, (pos += blockSize32), r); // V[i] = BlockMix(V[i-1]);
272
+ blockMixCb();
273
+ }
274
+ BlockMix(V, (N - 1) * blockSize32, B32, Pi, r); // Process last element
275
+ blockMixCb();
276
+ for (let i = 0; i < N; i++) {
277
+ // First u32 of the last 64-byte block (u32 is LE)
278
+ // RFC 7914 Integerify(X) uses the whole last 64-byte block, but mod N
279
+ // only depends on the low word here because N is a power of two and
280
+ // this implementation caps N at 2^32.
281
+ // & (N - 1) is % N as N is a power of 2, N & (N - 1) = 0 is checked
282
+ // above; >>> 0 for unsigned, input fits in u32.
283
+ const j = (B32[Pi + blockSize32 - 16] & (N - 1)) >>> 0; // j = Integrify(X) % iterations
284
+ // tmp = B ^ V[j]
285
+ for (let k = 0; k < blockSize32; k++) tmp[k] = B32[Pi + k] ^ V[j * blockSize32 + k];
286
+ BlockMix(tmp, 0, B32, Pi, r); // B = BlockMix(B ^ V[j])
287
+ blockMixCb();
288
+ }
289
+ }
290
+ swap32IfBE(B32);
291
+ return scryptOutput(password, dkLen, B, V, tmp);
292
+ }
293
+
294
+ /**
295
+ * Scrypt KDF from RFC 7914. Async version. See {@link ScryptOpts}.
296
+ * @param password - password or key material to derive from;
297
+ * JS string inputs are UTF-8 encoded first
298
+ * @param salt - unique salt bytes or string; JS string inputs are UTF-8 encoded first
299
+ * @param opts - Scrypt cost and memory parameters. `dkLen`, if provided,
300
+ * must be `>= 1` per RFC 7914 §2. `asyncTick` is only a local
301
+ * scheduler-yield control for this JS wrapper, not part of RFC 7914.
302
+ * See {@link ScryptOpts}.
303
+ * @returns Promise resolving to derived key bytes.
304
+ * @throws If the Scrypt cost, memory, or callback options are invalid. {@link Error}
305
+ * @example
306
+ * Derive a key with scrypt asynchronously.
307
+ * ```ts
308
+ * await scryptAsync('password', 'salt', { N: 2**18, r: 8, p: 1, dkLen: 32 });
309
+ * ```
310
+ * @example
311
+ * Derive a key asynchronously with small demo costs and progress/memory controls.
312
+ * ```ts
313
+ * await scryptAsync('password', 'salt', {
314
+ * N: 16,
315
+ * r: 8,
316
+ * p: 1,
317
+ * dkLen: 32,
318
+ * maxmem: 1024 * 1024,
319
+ * asyncTick: 1,
320
+ * onProgress(progress) {
321
+ * if (progress > 1) throw new Error('invalid progress');
322
+ * },
323
+ * });
324
+ * ```
325
+ */
326
+ export async function scryptAsync(
327
+ password: TArg<KDFInput>,
328
+ salt: TArg<KDFInput>,
329
+ opts: ScryptOpts
330
+ ): Promise<TRet<Uint8Array>> {
331
+ const { N, r, p, dkLen, blockSize32, V, B32, B, tmp, blockMixCb, asyncTick } = scryptInit(
332
+ password,
333
+ salt,
334
+ opts
335
+ );
336
+ // One failure handler covers both yield boundaries without putting the hot loops in a try block.
337
+ const abort = () => clean(B, V, tmp);
338
+ swap32IfBE(B32);
339
+ for (let pi = 0; pi < p; pi++) {
340
+ const Pi = blockSize32 * pi;
341
+ for (let i = 0; i < blockSize32; i++) V[i] = B32[Pi + i]; // V[0] = B[i]
342
+ let pos = 0;
343
+ await asyncLoop(
344
+ N - 1,
345
+ asyncTick,
346
+ () => {
347
+ BlockMix(V, pos, V, (pos += blockSize32), r); // V[i] = BlockMix(V[i-1]);
348
+ blockMixCb();
349
+ },
350
+ abort
351
+ );
352
+ BlockMix(V, (N - 1) * blockSize32, B32, Pi, r); // Process last element
353
+ blockMixCb();
354
+ await asyncLoop(
355
+ N,
356
+ asyncTick,
357
+ () => {
358
+ // First u32 of the last 64-byte block (u32 is LE)
359
+ // RFC 7914 Integerify(X) uses the whole last 64-byte block, but mod N
360
+ // only depends on the low word here because N is a power of two and
361
+ // this implementation caps N at 2^32.
362
+ // & (N - 1) is % N as N is a power of 2, N & (N - 1) = 0 is checked
363
+ // above; >>> 0 for unsigned, input fits in u32.
364
+ const j = (B32[Pi + blockSize32 - 16] & (N - 1)) >>> 0; // j = Integrify(X) % iterations
365
+ // tmp = B ^ V[j]
366
+ for (let k = 0; k < blockSize32; k++) tmp[k] = B32[Pi + k] ^ V[j * blockSize32 + k];
367
+ BlockMix(tmp, 0, B32, Pi, r); // B = BlockMix(B ^ V[j])
368
+ blockMixCb();
369
+ },
370
+ abort
371
+ );
372
+ }
373
+ swap32IfBE(B32);
374
+ return scryptOutput(password, dkLen, B, V, tmp);
375
+ }