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,973 @@
1
+ /**
2
+ * SHA3 (keccak) addons.
3
+ *
4
+ * * cSHAKE, KMAC, TupleHash, ParallelHash + XOF variants from
5
+ * {@link https://csrc.nist.gov/pubs/sp/800/185/final | NIST SP 800-185}
6
+ * * KangarooTwelve 🦘 and TurboSHAKE - reduced-round keccak from
7
+ * {@link https://datatracker.ietf.org/doc/rfc9861/ | RFC 9861}
8
+ * * KeccakPRG: Pseudo-random generator based on Keccak
9
+ * ({@link https://keccak.team/files/CSF-0.1.pdf | pdf})
10
+ * @module
11
+ */
12
+ import { Keccak } from "./sha3.js";
13
+ import { abytes, aexists, anumber, checkOpts, clean, copyBytes, createHasher, randomBytes, kdfInputToBytes, u32, } from "./utils.js";
14
+ // cSHAKE && KMAC (NIST SP800-185)
15
+ const _8n = /* @__PURE__ */ BigInt(8);
16
+ const _ffn = /* @__PURE__ */ BigInt(0xff);
17
+ // It is safe to use bigints here, since they used only for length encoding (not actual data).
18
+ // We use bigints in sha256 for lengths too.
19
+ // Callers are still expected to supply SP 800-185-valid lengths
20
+ // (`0 <= x < 2^2040`); this helper does not enforce that bound.
21
+ // Minimal big-endian bytes of `n`, at least one byte long (SP 800-185 §2.3.1).
22
+ function encodeBytes(n) {
23
+ n = BigInt(n);
24
+ const res = [Number(n & _ffn)];
25
+ n >>= _8n;
26
+ for (; n > 0; n >>= _8n)
27
+ res.unshift(Number(n & _ffn));
28
+ return res;
29
+ }
30
+ // left_encode(n): byte count is prepended.
31
+ function leftEncode(n) {
32
+ const res = encodeBytes(n);
33
+ res.unshift(res.length);
34
+ return new Uint8Array(res);
35
+ }
36
+ // right_encode(n): byte count is appended.
37
+ function rightEncode(n) {
38
+ const res = encodeBytes(n);
39
+ res.push(res.length);
40
+ return new Uint8Array(res);
41
+ }
42
+ // `dkLen` range validation is deferred to the downstream Keccak constructor.
43
+ function chooseLen(opts, outputLen) {
44
+ opts = checkOpts({}, opts);
45
+ return opts.dkLen === undefined ? outputLen : opts.dkLen;
46
+ }
47
+ const abytesOrZero = (buf, title = '') => {
48
+ if (buf === undefined)
49
+ return EMPTY_BUFFER;
50
+ abytes(buf, undefined, title);
51
+ return buf;
52
+ };
53
+ // NOTE: second modulo is necessary since we don't need to add padding if the
54
+ // current element takes a whole block.
55
+ // Callers only pass the fixed positive Keccak rates here (`168` or `136`);
56
+ // `block <= 0` is not validated locally.
57
+ const getPadding = (len, block) => new Uint8Array((block - (len % block)) % block);
58
+ // bytepad(X1 || X2 || ..., rate): absorbs left_encode(rate), then each chunk, then zero-pads
59
+ // to a rate boundary. Encode and pad inplace to avoid unneccesary memory copies/slices so we
60
+ // don't need to zero them later. `rate` is the current cSHAKE/KMAC/TupleHash/ParallelHash
61
+ // block length.
62
+ function bytepadUpdate(h, ...chunks) {
63
+ const hash = h;
64
+ const blockLenBytes = leftEncode(hash.blockLen);
65
+ hash.update(blockLenBytes);
66
+ let totalLen = blockLenBytes.length;
67
+ for (const chunk of chunks) {
68
+ hash.update(chunk);
69
+ totalLen += chunk.length;
70
+ }
71
+ hash.update(getPadding(totalLen, hash.blockLen));
72
+ return hash;
73
+ }
74
+ // Personalization
75
+ function cshakePers(h, opts = {}) {
76
+ const hash = h;
77
+ opts = checkOpts({}, opts);
78
+ if (opts.personalization === undefined && opts.NISTfn === undefined)
79
+ return hash;
80
+ // bytepad(encode_string(N) || encode_string(S), rate)
81
+ const fn = opts.NISTfn === undefined ? EMPTY_BUFFER : kdfInputToBytes(opts.NISTfn);
82
+ const fnLen = leftEncode(_8n * BigInt(fn.length)); // length in bits
83
+ const pers = abytesOrZero(opts.personalization, 'personalization');
84
+ const persLen = leftEncode(_8n * BigInt(pers.length)); // length in bits
85
+ if (!fn.length && !pers.length)
86
+ return hash;
87
+ // SP 800-185 cSHAKE appends `00` instead of SHAKE's `1111`; in this Keccak implementation
88
+ // that changes the delimited suffix byte from `0x1f` to `0x04` once N or S is non-empty.
89
+ hash.suffix = 0x04;
90
+ return bytepadUpdate(hash, fnLen, fn, persLen, pers);
91
+ }
92
+ const gencShake = (suffix, blockLen, outputLen) => createHasher((opts = {}) => cshakePers(new Keccak(blockLen, suffix, chooseLen(opts, outputLen), true), opts));
93
+ /**
94
+ * 128-bit NIST cSHAKE XOF.
95
+ * @param msg - message bytes to hash
96
+ * @param opts - Optional output, personalization, and NIST function-name
97
+ * settings. When both `NISTfn` and `personalization` are empty,
98
+ * SP 800-185 defines this as plain SHAKE128. Defaults to 16 output bytes
99
+ * when `dkLen` is omitted. See {@link cShakeOpts}.
100
+ * @returns Digest bytes.
101
+ * @example
102
+ * Hash a message with cSHAKE128.
103
+ * ```ts
104
+ * cshake128(new Uint8Array([1, 2, 3]), { dkLen: 32 });
105
+ * ```
106
+ * @example
107
+ * Hash a message with SP 800-185 domain separation.
108
+ * ```ts
109
+ * cshake128(new Uint8Array([1, 2, 3]), {
110
+ * dkLen: 32,
111
+ * NISTfn: 'Email Signature',
112
+ * personalization: new Uint8Array([1, 2, 3]),
113
+ * });
114
+ * ```
115
+ */
116
+ export const cshake128 = /* @__PURE__ */ gencShake(0x1f, 168, 16);
117
+ /**
118
+ * 256-bit NIST cSHAKE XOF.
119
+ * @param msg - message bytes to hash
120
+ * @param opts - Optional output, personalization, and NIST function-name
121
+ * settings. When both `NISTfn` and `personalization` are empty,
122
+ * SP 800-185 defines this as plain SHAKE256. Defaults to 32 output bytes
123
+ * when `dkLen` is omitted. See {@link cShakeOpts}.
124
+ * @returns Digest bytes.
125
+ * @example
126
+ * Hash a message with cSHAKE256.
127
+ * ```ts
128
+ * cshake256(new Uint8Array([1, 2, 3]), { dkLen: 64 });
129
+ * ```
130
+ */
131
+ export const cshake256 = /* @__PURE__ */ gencShake(0x1f, 136, 32);
132
+ /**
133
+ * Internal KMAC class.
134
+ * SP 800-185 §8.4.1 still recommends keys at least as long as the target
135
+ * security strength.
136
+ */
137
+ export class _KMAC extends Keccak {
138
+ constructor(blockLen, outputLen, enableXOF, key, opts = {}) {
139
+ super(blockLen, 0x1f, outputLen, enableXOF);
140
+ // Preload T = bytepad(encode_string("KMAC") || encode_string(S), rate); later updates append
141
+ // newX = bytepad(encode_string(K), rate) || X and `finish()` appends right_encode(L or 0).
142
+ cshakePers(this, { NISTfn: 'KMAC', personalization: opts.personalization });
143
+ abytes(key, undefined, 'key');
144
+ // 1. newX = bytepad(encode_string(K), rate) || X || right_encode(L),
145
+ // with `rate = this.blockLen`.
146
+ bytepadUpdate(this, leftEncode(_8n * BigInt(key.length)), key);
147
+ }
148
+ finish() {
149
+ // SP 800-185 uses right_encode(L) for fixed-length KMAC and right_encode(0) for KMACXOF.
150
+ // outputLen in bits
151
+ if (!this.finished)
152
+ this.update(rightEncode(this.enableXOF ? 0 : _8n * BigInt(this.outputLen)));
153
+ super.finish();
154
+ }
155
+ _cloneInto(to) {
156
+ // Create new instance without calling constructor since the key
157
+ // is already in state and we don't know it.
158
+ // Force "to" to be instance of KMAC instead of Sha3.
159
+ if (!to) {
160
+ to = Object.create(Object.getPrototypeOf(this), {});
161
+ to.state = this.state.slice();
162
+ to.blockLen = this.blockLen;
163
+ to.state32 = u32(to.state);
164
+ }
165
+ return super._cloneInto(to);
166
+ }
167
+ clone() {
168
+ return this._cloneInto();
169
+ }
170
+ }
171
+ function genKmac(blockLen, outputLen, xof = false) {
172
+ // One-shot XOF wrappers still finalize via `.digest()` because `_KMAC`
173
+ // already bakes the requested output length into the state.
174
+ const kmac = (key, message, opts) => kmac.create(key, opts).update(message).digest();
175
+ kmac.create = (key, opts = {}) => new _KMAC(blockLen, chooseLen(opts, outputLen), xof, key, opts);
176
+ // Same metadata + freeze as `createHasher()` wrappers, so duck-typed
177
+ // consumers (e.g. `ahash()`) treat all wrappers alike.
178
+ kmac.outputLen = outputLen;
179
+ kmac.blockLen = blockLen;
180
+ kmac.canXOF = xof;
181
+ return Object.freeze(kmac);
182
+ }
183
+ /**
184
+ * 128-bit Keccak MAC.
185
+ * @param key - MAC key bytes
186
+ * @param message - message bytes to authenticate
187
+ * @param opts - Optional output and personalization settings. Defaults to
188
+ * 16 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
189
+ * @returns Authentication tag bytes.
190
+ * @example
191
+ * Authenticate a message with KMAC128.
192
+ * ```ts
193
+ * const key = new Uint8Array([1, 2, 3]);
194
+ * const message = new Uint8Array([4, 5, 6]);
195
+ * kmac128(key, message);
196
+ * ```
197
+ * @example
198
+ * Authenticate a message with output options and an incremental state.
199
+ * ```ts
200
+ * const key = new Uint8Array([1, 2, 3]);
201
+ * const message = new Uint8Array([4, 5, 6]);
202
+ * const opts = { dkLen: 32, personalization: new Uint8Array([7, 8, 9]) };
203
+ * const tag = kmac128(key, message, opts);
204
+ * const out = new Uint8Array(32);
205
+ * kmac128.create(key, { dkLen: 32 }).update(message).digestInto(out);
206
+ * ```
207
+ */
208
+ export const kmac128 = /* @__PURE__ */ genKmac(168, 16);
209
+ /**
210
+ * 256-bit Keccak MAC.
211
+ * @param key - MAC key bytes
212
+ * @param message - message bytes to authenticate
213
+ * @param opts - Optional output and personalization settings. Defaults to
214
+ * 32 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
215
+ * @returns Authentication tag bytes.
216
+ * @example
217
+ * Authenticate a message with KMAC256.
218
+ * ```ts
219
+ * kmac256(new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6]));
220
+ * ```
221
+ */
222
+ export const kmac256 = /* @__PURE__ */ genKmac(136, 32);
223
+ /**
224
+ * 128-bit Keccak-MAC XOF.
225
+ * @param key - MAC key bytes
226
+ * @param message - message bytes to authenticate
227
+ * @param opts - Optional output and personalization settings. Defaults to
228
+ * 16 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
229
+ * @returns Authentication tag bytes.
230
+ * @example
231
+ * Authenticate a message with KMAC128 XOF output.
232
+ * ```ts
233
+ * kmac128xof(new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6]), { dkLen: 32 });
234
+ * ```
235
+ */
236
+ export const kmac128xof = /* @__PURE__ */ genKmac(168, 16, true);
237
+ /**
238
+ * 256-bit Keccak-MAC XOF.
239
+ * @param key - MAC key bytes
240
+ * @param message - message bytes to authenticate
241
+ * @param opts - Optional output and personalization settings. Defaults to
242
+ * 32 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
243
+ * @returns Authentication tag bytes.
244
+ * @example
245
+ * Authenticate a message with KMAC256 XOF output.
246
+ * ```ts
247
+ * kmac256xof(new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6]), { dkLen: 64 });
248
+ * ```
249
+ */
250
+ export const kmac256xof = /* @__PURE__ */ genKmac(136, 32, true);
251
+ /**
252
+ * Internal TupleHash class for byte-array tuple elements.
253
+ * This implementation relies on SP 800-185's byte-oriented encoding form
254
+ * rather than arbitrary bit strings.
255
+ */
256
+ export class _TupleHash extends Keccak {
257
+ // Cheaper than a per-instance `this.update = ...` closure: switches the class-method
258
+ // update from plain absorption (during the cSHAKE preload) to tuple-element encoding.
259
+ tupleMode = false;
260
+ constructor(blockLen, outputLen, enableXOF, opts = {}) {
261
+ super(blockLen, 0x1f, outputLen, enableXOF);
262
+ cshakePers(this, { NISTfn: 'TupleHash', personalization: opts.personalization });
263
+ this.tupleMode = true;
264
+ }
265
+ update(data) {
266
+ if (!this.tupleMode)
267
+ return super.update(data);
268
+ abytes(data);
269
+ // SP 800-185 encodes each tuple element as
270
+ // encode_string(X[i]) = left_encode(len(X[i])) || X[i].
271
+ super.update(leftEncode(_8n * BigInt(data.length)));
272
+ super.update(data);
273
+ return this;
274
+ }
275
+ finish() {
276
+ // SP 800-185 uses right_encode(L) for fixed-length TupleHash
277
+ // and right_encode(0) for TupleHashXOF.
278
+ if (!this.finished)
279
+ // outputLen in bits
280
+ super.update(rightEncode(this.enableXOF ? 0 : _8n * BigInt(this.outputLen)));
281
+ super.finish();
282
+ }
283
+ _cloneInto(to) {
284
+ to ||= new _TupleHash(this.blockLen, this.outputLen, this.enableXOF);
285
+ to.tupleMode = this.tupleMode;
286
+ return super._cloneInto(to);
287
+ }
288
+ clone() {
289
+ return this._cloneInto();
290
+ }
291
+ }
292
+ function genTuple(blockLen, outputLen, xof = false) {
293
+ // One-shot XOF wrappers still use `.digest()` because `_TupleHash` stores
294
+ // the requested output length in the state itself.
295
+ const tuple = (messages, opts) => {
296
+ const h = tuple.create(opts);
297
+ if (!Array.isArray(messages))
298
+ throw new Error('expected array of messages');
299
+ for (const msg of messages)
300
+ h.update(msg);
301
+ return h.digest();
302
+ };
303
+ tuple.create = (opts = {}) => new _TupleHash(blockLen, chooseLen(opts, outputLen), xof, opts);
304
+ // Same metadata + freeze as `createHasher()` wrappers, so duck-typed
305
+ // consumers (e.g. `ahash()`) treat all wrappers alike.
306
+ tuple.outputLen = outputLen;
307
+ tuple.blockLen = blockLen;
308
+ tuple.canXOF = xof;
309
+ return Object.freeze(tuple);
310
+ }
311
+ /**
312
+ * 128-bit TupleHASH. `tuple(['ab', 'cd']) != tuple(['a', 'bcd'])`.
313
+ * @param messages - ordered byte-array tuple
314
+ * @param opts - Optional output and personalization settings. Defaults to
315
+ * 16 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
316
+ * @returns Digest bytes.
317
+ * @example
318
+ * Hash a tuple of byte arrays with TupleHash128.
319
+ * ```ts
320
+ * tuplehash128([new Uint8Array([1]), new Uint8Array([2])]);
321
+ * ```
322
+ */
323
+ export const tuplehash128 = /* @__PURE__ */ genTuple(168, 16);
324
+ /**
325
+ * 256-bit TupleHASH. `tuple(['ab', 'cd']) != tuple(['a', 'bcd'])`.
326
+ * @param messages - ordered byte-array tuple
327
+ * @param opts - Optional output and personalization settings. Defaults to
328
+ * 32 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
329
+ * @returns Digest bytes.
330
+ * @example
331
+ * Hash a tuple of byte arrays with TupleHash256.
332
+ * ```ts
333
+ * tuplehash256([new Uint8Array([1]), new Uint8Array([2])]);
334
+ * ```
335
+ */
336
+ export const tuplehash256 = /* @__PURE__ */ genTuple(136, 32);
337
+ /**
338
+ * 128-bit TupleHASH XOF.
339
+ * @param messages - ordered byte-array tuple
340
+ * @param opts - Optional output and personalization settings. Defaults to
341
+ * 16 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
342
+ * @returns Digest bytes.
343
+ * @example
344
+ * Hash a tuple of byte arrays with TupleHash128 XOF output.
345
+ * ```ts
346
+ * tuplehash128xof([new Uint8Array([1]), new Uint8Array([2])], { dkLen: 32 });
347
+ * ```
348
+ */
349
+ export const tuplehash128xof = /* @__PURE__ */ genTuple(168, 16, true);
350
+ /**
351
+ * 256-bit TupleHASH XOF.
352
+ * @param messages - ordered byte-array tuple
353
+ * @param opts - Optional output and personalization settings. Defaults to
354
+ * 32 output bytes when `dkLen` is omitted. See {@link cShakeOpts}.
355
+ * @returns Digest bytes.
356
+ * @example
357
+ * Hash a tuple of byte arrays with TupleHash256 XOF output.
358
+ * ```ts
359
+ * tuplehash256xof([new Uint8Array([1]), new Uint8Array([2])], { dkLen: 64 });
360
+ * ```
361
+ */
362
+ export const tuplehash256xof = /* @__PURE__ */ genTuple(136, 32, true);
363
+ /** Internal Parallel Keccak Hash class. */
364
+ export class _ParallelHash extends Keccak {
365
+ leafHash;
366
+ leafCons;
367
+ // Pristine leaf instance cloned into `leafHash` per chunk: with the default
368
+ // 8-byte chunks, constructing a fresh leaf per chunk costs ~15% (measured).
369
+ leafTemplate;
370
+ // Reused chaining-value buffer for leaf digests.
371
+ leafCV;
372
+ chunkPos = 0; // Position of current block in chunk
373
+ chunksDone = 0; // How many chunks we already have
374
+ chunkLen;
375
+ // Cheaper than a per-instance `this.update = ...` closure: switches the class-method
376
+ // update from plain absorption (during the cSHAKE preload) to leaf chunking.
377
+ leafMode = false;
378
+ constructor(blockLen, outputLen, leafCons, enableXOF, opts = {}) {
379
+ super(blockLen, 0x1f, outputLen, enableXOF);
380
+ cshakePers(this, { NISTfn: 'ParallelHash', personalization: opts.personalization });
381
+ this.leafCons = leafCons;
382
+ let { blockLen: B = 8 } = opts;
383
+ anumber(B);
384
+ // blockLen=0 makes take=0 in update(), so pos never advances and the hash hangs.
385
+ if (B < 1)
386
+ throw new Error('"blockLen" must be >= 1, got ' + B);
387
+ this.chunkLen = B;
388
+ // SP 800-185 initializes z = left_encode(B); each completed chunk appends
389
+ // one fixed-size cSHAKE leaf digest before finish() adds right_encode(n)
390
+ // and right_encode(L or 0).
391
+ super.update(leftEncode(B));
392
+ this.leafMode = true;
393
+ }
394
+ flushLeaf() {
395
+ const cv = (this.leafCV ||= new Uint8Array(this.leafHash.outputLen));
396
+ this.leafHash.digestInto(cv);
397
+ super.update(cv);
398
+ this.chunksDone++;
399
+ }
400
+ update(data) {
401
+ if (!this.leafMode)
402
+ return super.update(data);
403
+ aexists(this);
404
+ abytes(data);
405
+ const { chunkLen, leafCons } = this;
406
+ for (let pos = 0, len = data.length; pos < len;) {
407
+ if (this.chunkPos == chunkLen || !this.leafHash) {
408
+ if (this.leafHash)
409
+ this.flushLeaf();
410
+ // Clone a pristine template instead of re-running the constructor;
411
+ // resurrects the just-digested leaf allocation in place.
412
+ this.leafTemplate ||= leafCons();
413
+ this.leafHash = this.leafTemplate._cloneInto(this.leafHash);
414
+ this.chunkPos = 0;
415
+ }
416
+ const take = Math.min(chunkLen - this.chunkPos, len - pos);
417
+ this.leafHash.update(data.subarray(pos, pos + take));
418
+ this.chunkPos += take;
419
+ pos += take;
420
+ }
421
+ return this;
422
+ }
423
+ finish() {
424
+ if (this.finished)
425
+ return;
426
+ if (this.leafHash)
427
+ this.flushLeaf();
428
+ // SP 800-185 finishes ParallelHash as
429
+ // z || right_encode(n) || right_encode(L); XOF mode replaces
430
+ // right_encode(L) with right_encode(0).
431
+ super.update(rightEncode(this.chunksDone));
432
+ // outputLen in bits
433
+ super.update(rightEncode(this.enableXOF ? 0 : _8n * BigInt(this.outputLen)));
434
+ super.finish();
435
+ }
436
+ // Overriding hides Keccak's flat implementation, which would otherwise be inherited
437
+ // and silently miss the tree state (leaf hash, chunk counters).
438
+ _cloneInto(to) {
439
+ to ||= new _ParallelHash(this.blockLen, this.outputLen, this.leafCons, this.enableXOF);
440
+ to.leafCons = this.leafCons;
441
+ // Clone the cached template/CV as regular state: this also overwrites
442
+ // stale wrong-variant values on reused destinations.
443
+ if (this.leafTemplate)
444
+ to.leafTemplate = this.leafTemplate._cloneInto(to.leafTemplate);
445
+ else if (to.leafTemplate) {
446
+ to.leafTemplate.destroy();
447
+ to.leafTemplate = undefined;
448
+ }
449
+ if (this.leafCV) {
450
+ if (to.leafCV && to.leafCV.length === this.leafCV.length)
451
+ to.leafCV.set(this.leafCV);
452
+ else
453
+ to.leafCV = this.leafCV.slice();
454
+ }
455
+ else
456
+ to.leafCV = undefined;
457
+ // Reused destinations can carry a stale partial leaf
458
+ // when the source is still on the root sponge.
459
+ if (this.leafHash)
460
+ to.leafHash = this.leafHash._cloneInto(to.leafHash);
461
+ else if (to.leafHash) {
462
+ to.leafHash.destroy();
463
+ to.leafHash = undefined;
464
+ }
465
+ to.chunkPos = this.chunkPos;
466
+ to.chunkLen = this.chunkLen;
467
+ to.chunksDone = this.chunksDone;
468
+ to.leafMode = this.leafMode;
469
+ return super._cloneInto(to);
470
+ }
471
+ destroy() {
472
+ super.destroy.call(this);
473
+ if (this.leafHash)
474
+ this.leafHash.destroy();
475
+ if (this.leafTemplate)
476
+ this.leafTemplate.destroy();
477
+ if (this.leafCV)
478
+ clean(this.leafCV);
479
+ }
480
+ clone() {
481
+ return this._cloneInto();
482
+ }
483
+ }
484
+ function genPrl(blockLen, outputLen, leaf, xof = false) {
485
+ const parallel = (message, opts) => parallel.create(opts).update(message).digest();
486
+ parallel.create = (opts = {}) => new _ParallelHash(blockLen, chooseLen(opts, outputLen),
487
+ // SP 800-185 fixes leaf digests at 256 bits for ParallelHash128 and
488
+ // 512 bits for ParallelHash256; only the final cSHAKE output uses the
489
+ // caller-selected dkLen.
490
+ () => leaf.create({ dkLen: 2 * outputLen }), xof, opts);
491
+ // Same metadata + freeze as `createHasher()` wrappers.
492
+ parallel.outputLen = outputLen;
493
+ parallel.blockLen = blockLen;
494
+ parallel.canXOF = xof;
495
+ return Object.freeze(parallel);
496
+ }
497
+ /**
498
+ * 128-bit ParallelHash. In JS, it is not parallel.
499
+ * @param msg - message bytes to hash
500
+ * @param opts - Optional output, personalization, and chunking settings.
501
+ * Defaults to 16 output bytes when `dkLen` is omitted.
502
+ * See {@link ParallelOpts}.
503
+ * @returns Digest bytes.
504
+ * @example
505
+ * Hash a message with ParallelHash128.
506
+ * ```ts
507
+ * parallelhash128(new Uint8Array([1, 2, 3]));
508
+ * ```
509
+ * @example
510
+ * Hash a message with chunking and personalization settings.
511
+ * ```ts
512
+ * parallelhash128(new Uint8Array([1, 2, 3]), {
513
+ * blockLen: 8,
514
+ * dkLen: 32,
515
+ * personalization: new Uint8Array([4, 5, 6]),
516
+ * });
517
+ * ```
518
+ */
519
+ export const parallelhash128 = /* @__PURE__ */ genPrl(168, 16, cshake128);
520
+ /**
521
+ * 256-bit ParallelHash. In JS, it is not parallel.
522
+ * @param msg - message bytes to hash
523
+ * @param opts - Optional output, personalization, and chunking settings.
524
+ * Defaults to 32 output bytes when `dkLen` is omitted.
525
+ * See {@link ParallelOpts}.
526
+ * @returns Digest bytes.
527
+ * @example
528
+ * Hash a message with ParallelHash256.
529
+ * ```ts
530
+ * parallelhash256(new Uint8Array([1, 2, 3]));
531
+ * ```
532
+ */
533
+ export const parallelhash256 = /* @__PURE__ */ genPrl(136, 32, cshake256);
534
+ /**
535
+ * 128-bit ParallelHash XOF. In JS, it is not parallel.
536
+ * @param msg - message bytes to hash
537
+ * @param opts - Optional output, personalization, and chunking settings.
538
+ * Defaults to 16 output bytes when `dkLen` is omitted.
539
+ * See {@link ParallelOpts}.
540
+ * @returns Digest bytes.
541
+ * @example
542
+ * Hash a message with ParallelHash128 XOF output.
543
+ * ```ts
544
+ * parallelhash128xof(new Uint8Array([1, 2, 3]), { dkLen: 32 });
545
+ * ```
546
+ */
547
+ export const parallelhash128xof = /* @__PURE__ */ genPrl(168, 16, cshake128, true);
548
+ /**
549
+ * 256-bit ParallelHash XOF. In JS, it is not parallel.
550
+ * @param msg - message bytes to hash
551
+ * @param opts - Optional output, personalization, and chunking settings.
552
+ * Defaults to 32 output bytes when `dkLen` is omitted.
553
+ * See {@link ParallelOpts}.
554
+ * @returns Digest bytes.
555
+ * @example
556
+ * Hash a message with ParallelHash256 XOF output.
557
+ * ```ts
558
+ * parallelhash256xof(new Uint8Array([1, 2, 3]), { dkLen: 64 });
559
+ * ```
560
+ */
561
+ export const parallelhash256xof = /* @__PURE__ */ genPrl(136, 32, cshake256, true);
562
+ const genTurbo = (blockLen, outputLen) => createHasher((opts = {}) => {
563
+ opts = checkOpts({}, opts);
564
+ const D = opts.D === undefined ? 0x1f : opts.D;
565
+ // RFC 9861 §2.1 fixes the default `D = 0x1f`; §2.2 defines the 12-round
566
+ // TurboSHAKE family selected here.
567
+ if (!Number.isSafeInteger(D) || D < 0x01 || D > 0x7f)
568
+ throw new Error('"D" (domain separation byte) must be 0x01..0x7f, got: ' + D);
569
+ const dkLen = chooseLen(opts, outputLen);
570
+ // RFC 9861 §§2.1-2.2 define output length L as a positive integer.
571
+ if (dkLen < 1)
572
+ throw new Error('"dkLen" must be >= 1');
573
+ return new Keccak(blockLen, D, dkLen, true, 12);
574
+ });
575
+ /**
576
+ * TurboSHAKE 128-bit: reduced 12-round keccak.
577
+ * Should've been a simple "shake with 12 rounds", but we got a whole new
578
+ * spec about Turbo SHAKE Pro MAX.
579
+ * @param msg - message bytes to hash
580
+ * @param opts - Optional output-length and domain-separation settings.
581
+ * RFC 9861 §2.1 defaults `D` to `0x1f`. Defaults to 32 output bytes when
582
+ * `dkLen` is omitted. See {@link TurboshakeOpts}.
583
+ * @returns Digest bytes.
584
+ * @example
585
+ * Hash a message with TurboSHAKE128.
586
+ * ```ts
587
+ * turboshake128(new Uint8Array([1, 2, 3]), { dkLen: 32 });
588
+ * ```
589
+ * @example
590
+ * Hash a message with an explicit domain-separation byte.
591
+ * ```ts
592
+ * turboshake128(new Uint8Array([1, 2, 3]), { dkLen: 32, D: 0x1f });
593
+ * ```
594
+ */
595
+ export const turboshake128 = /* @__PURE__ */ genTurbo(168, 32);
596
+ /**
597
+ * TurboSHAKE 256-bit: reduced 12-round keccak.
598
+ * @param msg - message bytes to hash
599
+ * @param opts - Optional output-length and domain-separation settings.
600
+ * RFC 9861 §2.1 defaults `D` to `0x1f`. Defaults to 64 output bytes when
601
+ * `dkLen` is omitted. See {@link TurboshakeOpts}.
602
+ * @returns Digest bytes.
603
+ * @example
604
+ * Hash a message with TurboSHAKE256.
605
+ * ```ts
606
+ * turboshake256(new Uint8Array([1, 2, 3]), { dkLen: 64 });
607
+ * ```
608
+ */
609
+ export const turboshake256 = /* @__PURE__ */ genTurbo(136, 64);
610
+ // Same as NIST rightEncode, but returns `[0]` for the zero string.
611
+ // Callers still need to keep `x < 256^255` per RFC 9861 §3.3.
612
+ function rightEncodeK12(n) {
613
+ n = BigInt(n);
614
+ const res = [];
615
+ for (; n > 0; n >>= _8n)
616
+ res.unshift(Number(n & _ffn));
617
+ res.push(res.length);
618
+ return Uint8Array.from(res);
619
+ }
620
+ const EMPTY_BUFFER = /* @__PURE__ */ Uint8Array.of();
621
+ // RFC 9861 §3.2 FinalNode prefix for S_0 and the CV-list terminator.
622
+ const K12_TREE = /* @__PURE__ */ Uint8Array.from([3, 0, 0, 0, 0, 0, 0, 0]);
623
+ const K12_FINAL = /* @__PURE__ */ Uint8Array.from([0xff, 0xff]);
624
+ /** Internal K12 hash class. */
625
+ export class _KangarooTwelve extends Keccak {
626
+ chunkLen = 8192;
627
+ leafHash;
628
+ // Pristine leaf instance cloned into `leafHash` per chunk, same pattern as _ParallelHash:
629
+ // streaming reuses two leaf allocations total instead of one per 8KB chunk.
630
+ leafTemplate;
631
+ // Reused chaining-value buffer for leaf digests.
632
+ leafCV;
633
+ leafLen;
634
+ personalization;
635
+ chunkPos = 0; // Position of current block in chunk
636
+ chunksDone = 0; // How many chunks we already have
637
+ constructor(blockLen, leafLen, outputLen, rounds, opts) {
638
+ super(blockLen, 0x07, outputLen, true, rounds);
639
+ opts = checkOpts({}, opts);
640
+ // RFC 9861 §3 defines output length L as a positive integer.
641
+ if (outputLen < 1)
642
+ throw new Error('"dkLen" must be >= 1');
643
+ this.leafLen = leafLen;
644
+ this.personalization =
645
+ opts.personalization === undefined
646
+ ? EMPTY_BUFFER
647
+ : copyBytes(abytes(opts.personalization, undefined, 'personalization'));
648
+ }
649
+ update(data) {
650
+ aexists(this);
651
+ abytes(data);
652
+ const { chunkLen, blockLen, leafLen, rounds } = this;
653
+ for (let pos = 0, len = data.length; pos < len;) {
654
+ if (this.chunkPos == chunkLen) {
655
+ if (this.leafHash)
656
+ this.flushLeaf();
657
+ else {
658
+ // RFC 9861 §3.2 switches from SingleNode (`07`) to FinalNode (`06`)
659
+ // once S exceeds 8192 bytes and prefixes S_0 with
660
+ // `03 00 00 00 00 00 00 00`.
661
+ this.suffix = 0x06; // Its safe to change suffix here since its used only in digest()
662
+ super.update(K12_TREE);
663
+ }
664
+ // Secondary chunks S_1..S_(n-1) become fixed-length
665
+ // CV_i = TurboSHAKE*(S_i, `0B`, 32|64) chaining values.
666
+ // Clone a pristine template instead of re-running the constructor;
667
+ // resurrects the just-digested leaf allocation in place.
668
+ this.leafTemplate ??= new Keccak(blockLen, 0x0b, leafLen, false, rounds);
669
+ this.leafHash = this.leafTemplate._cloneInto(this.leafHash);
670
+ this.chunksDone++;
671
+ this.chunkPos = 0;
672
+ }
673
+ const take = Math.min(chunkLen - this.chunkPos, len - pos);
674
+ const chunk = data.subarray(pos, pos + take);
675
+ if (this.leafHash)
676
+ this.leafHash.update(chunk);
677
+ else
678
+ super.update(chunk);
679
+ this.chunkPos += take;
680
+ pos += take;
681
+ }
682
+ return this;
683
+ }
684
+ flushLeaf() {
685
+ const leafHash = this.leafHash;
686
+ const cv = (this.leafCV ||= new Uint8Array(leafHash.outputLen));
687
+ leafHash.digestInto(cv);
688
+ super.update(cv);
689
+ }
690
+ finish() {
691
+ if (this.finished)
692
+ return;
693
+ const { personalization } = this;
694
+ // RFC 9861 §3.2 forms S = M || C || length_encode(|C|) before any tree hashing logic.
695
+ this.update(personalization).update(rightEncodeK12(personalization.length));
696
+ // Leaf hash
697
+ if (this.leafHash) {
698
+ // Multi-chunk K12 appends
699
+ // CV_1..CV_(n-1) || length_encode(n-1) || `FF FF`
700
+ // before the final TurboSHAKE call.
701
+ this.flushLeaf();
702
+ super.update(rightEncodeK12(this.chunksDone));
703
+ super.update(K12_FINAL);
704
+ }
705
+ super.finish.call(this);
706
+ }
707
+ destroy() {
708
+ super.destroy.call(this);
709
+ if (this.leafHash)
710
+ this.leafHash.destroy();
711
+ if (this.leafTemplate)
712
+ this.leafTemplate.destroy();
713
+ if (this.leafCV)
714
+ clean(this.leafCV);
715
+ // Personalization is copied on create/clone, so destroy can wipe it
716
+ // without touching caller input.
717
+ if (this.personalization !== EMPTY_BUFFER)
718
+ clean(this.personalization);
719
+ this.personalization = EMPTY_BUFFER;
720
+ }
721
+ // Overriding hides Keccak's flat implementation, which would otherwise be inherited
722
+ // and silently miss the tree state (leaf hash, chunk counters).
723
+ _cloneInto(to) {
724
+ const { blockLen, leafLen, leafHash, outputLen, personalization, rounds } = this;
725
+ const fresh = to === undefined;
726
+ // Personalization is absorbed only during finish(), so clones need the same pending value.
727
+ to ||= new _KangarooTwelve(blockLen, leafLen, outputLen, rounds, {
728
+ personalization: personalization === EMPTY_BUFFER ? undefined : personalization,
729
+ });
730
+ super._cloneInto(to);
731
+ // Reused destinations can carry a stale leaf from an older multi-chunk state.
732
+ if (leafHash)
733
+ to.leafHash = leafHash._cloneInto(to.leafHash);
734
+ else if (to.leafHash) {
735
+ to.leafHash.destroy();
736
+ to.leafHash = undefined;
737
+ }
738
+ // Cached leaf state is part of a reusable clone: stale destroyed or wrong-variant values
739
+ // otherwise fail or change the digest only after the replacement crosses a tree boundary.
740
+ if (this.leafTemplate)
741
+ to.leafTemplate = this.leafTemplate._cloneInto(to.leafTemplate);
742
+ else if (to.leafTemplate) {
743
+ to.leafTemplate.destroy();
744
+ to.leafTemplate = undefined;
745
+ }
746
+ if (this.leafCV) {
747
+ if (to.leafCV && to.leafCV.length === this.leafCV.length)
748
+ to.leafCV.set(this.leafCV);
749
+ else
750
+ to.leafCV = this.leafCV.slice();
751
+ }
752
+ else
753
+ to.leafCV = undefined;
754
+ // Snapshot the pending personalization without aliasing source or caller-owned input.
755
+ if (!fresh) {
756
+ const old = to.personalization;
757
+ if (personalization === EMPTY_BUFFER) {
758
+ if (old !== EMPTY_BUFFER)
759
+ clean(old);
760
+ to.personalization = EMPTY_BUFFER;
761
+ }
762
+ else if (old === EMPTY_BUFFER || old.length !== personalization.length) {
763
+ const copy = copyBytes(personalization);
764
+ if (old !== EMPTY_BUFFER)
765
+ clean(old);
766
+ to.personalization = copy;
767
+ }
768
+ else {
769
+ // Reuse compatible private storage so live-destination clones neither allocate
770
+ // nor abandon user data.
771
+ old.set(personalization);
772
+ }
773
+ }
774
+ to.leafLen = this.leafLen;
775
+ to.chunkPos = this.chunkPos;
776
+ to.chunksDone = this.chunksDone;
777
+ return to;
778
+ }
779
+ clone() {
780
+ return this._cloneInto();
781
+ }
782
+ }
783
+ /**
784
+ * 128-bit KangarooTwelve (k12): reduced 12-round keccak.
785
+ * @param msg - message bytes to hash
786
+ * @param opts - Optional output and personalization settings. Defaults to
787
+ * 32 output bytes when `dkLen` is omitted. See {@link KangarooOpts}.
788
+ * @returns Digest bytes.
789
+ * @example
790
+ * Hash a message with KangarooTwelve-128.
791
+ * ```ts
792
+ * kt128(new Uint8Array([1, 2, 3]));
793
+ * ```
794
+ * @example
795
+ * Hash a message with KangarooTwelve-128 personalization.
796
+ * ```ts
797
+ * kt128(new Uint8Array([1, 2, 3]), {
798
+ * dkLen: 64,
799
+ * personalization: new Uint8Array([4, 5, 6]),
800
+ * });
801
+ * ```
802
+ */
803
+ export const kt128 = /* @__PURE__ */ createHasher((opts = {}) => new _KangarooTwelve(168, 32, chooseLen(opts, 32), 12, opts));
804
+ /**
805
+ * 256-bit KangarooTwelve (k12): reduced 12-round keccak.
806
+ * @param msg - message bytes to hash
807
+ * @param opts - Optional output and personalization settings. Defaults to
808
+ * 64 output bytes when `dkLen` is omitted. See {@link KangarooOpts}.
809
+ * @returns Digest bytes.
810
+ * @example
811
+ * Hash a message with KangarooTwelve-256.
812
+ * ```ts
813
+ * kt256(new Uint8Array([1, 2, 3]));
814
+ * ```
815
+ */
816
+ export const kt256 = /* @__PURE__ */ createHasher((opts = {}) => new _KangarooTwelve(136, 64, chooseLen(opts, 64), 12, opts));
817
+ const genHopMAC = (hash) => {
818
+ const kt = hash;
819
+ return ((key, message, personalization, dkLen) => kt(key, { personalization: kt(message, { personalization }), dkLen }));
820
+ };
821
+ /**
822
+ * 128-bit KangarooTwelve-based MAC.
823
+ *
824
+ * These untested (there is no test vectors or implementation available). Use at your own risk.
825
+ * HopMAC128(Key, M, C, L) = KT128(Key, KT128(M, C, 32), L)
826
+ * HopMAC256(Key, M, C, L) = KT256(Key, KT256(M, C, 64), L)
827
+ * The inner KangarooTwelve call always uses a fixed 32-byte digest here,
828
+ * regardless of the outer `dkLen`.
829
+ * @param key - MAC key bytes
830
+ * @param message - message bytes to authenticate
831
+ * @param personalization - personalization bytes mixed into the inner hash
832
+ * @param dkLen - optional output length in bytes
833
+ * @returns Authentication tag bytes.
834
+ * @example
835
+ * Authenticate a message with HopMAC128.
836
+ * ```ts
837
+ * HopMAC128(new Uint8Array([1]), new Uint8Array([2]), new Uint8Array([3]), 32);
838
+ * ```
839
+ */
840
+ export const HopMAC128 = /* @__PURE__ */ genHopMAC(kt128);
841
+ /**
842
+ * 256-bit KangarooTwelve-based MAC.
843
+ * Like `HopMAC128`, there are no test vectors or known independent
844
+ * implementations available for cross-checking.
845
+ * @param key - MAC key bytes
846
+ * @param message - message bytes to authenticate
847
+ * @param personalization - personalization bytes mixed into the inner hash
848
+ * @param dkLen - optional output length in bytes. The inner KangarooTwelve
849
+ * call still uses a fixed 64-byte digest here, regardless of the outer
850
+ * `dkLen`.
851
+ * @returns Authentication tag bytes.
852
+ * @example
853
+ * Authenticate a message with HopMAC256.
854
+ * ```ts
855
+ * HopMAC256(new Uint8Array([1]), new Uint8Array([2]), new Uint8Array([3]), 64);
856
+ * ```
857
+ */
858
+ export const HopMAC256 = /* @__PURE__ */ genHopMAC(kt256);
859
+ /**
860
+ * More at
861
+ * {@link https://github.com/XKCP/XKCP/tree/master/lib/high/Keccak/PRG}.
862
+ * Accepted capacities must keep `rho = 1598 - capacity` byte-aligned, and
863
+ * `.clean()` later also requires `rate > 801`.
864
+ */
865
+ export class _KeccakPRG extends Keccak {
866
+ rate;
867
+ entropyAdded = false;
868
+ constructor(capacity) {
869
+ anumber(capacity);
870
+ const rate = 1600 - capacity;
871
+ const rho = rate - 2;
872
+ // Rho must be full bytes
873
+ if (capacity < 0 || capacity > 1600 - 10 || rho % 8)
874
+ throw new Error('invalid capacity');
875
+ // blockLen = rho in bytes
876
+ super(rho / 8, 0, 0, true);
877
+ this.rate = rate;
878
+ this.posOut = Math.floor((rate + 7) / 8);
879
+ }
880
+ keccak() {
881
+ // Duplex padding
882
+ this.state[this.pos] ^= 0x01;
883
+ this.state[this.blockLen] ^= 0x02; // Rho is full bytes
884
+ super.keccak();
885
+ this.pos = 0;
886
+ this.posOut = 0;
887
+ }
888
+ update(data) {
889
+ super.update(data);
890
+ this.posOut = this.blockLen;
891
+ return this;
892
+ }
893
+ finish() { }
894
+ digestInto(_out) {
895
+ throw new Error('digest is not allowed, use .randomBytes() instead');
896
+ }
897
+ addEntropy(seed) {
898
+ // Check lifecycle before asking the system RNG for entropy that cannot be used.
899
+ aexists(this);
900
+ if (seed !== undefined) {
901
+ abytes(seed, undefined, 'seed');
902
+ if (seed.length === 0)
903
+ throw new Error('"seed" must not be empty');
904
+ }
905
+ const generated = seed === undefined;
906
+ const entropy = generated ? randomBytes() : seed;
907
+ try {
908
+ this.update(entropy);
909
+ this.entropyAdded = true;
910
+ }
911
+ finally {
912
+ // This temporary is library-owned; caller-provided entropy remains caller-owned.
913
+ if (generated)
914
+ clean(entropy);
915
+ }
916
+ }
917
+ xofInto(out) {
918
+ aexists(this, false);
919
+ if (!this.entropyAdded)
920
+ throw new Error('addEntropy() must be called before randomBytes()');
921
+ return super.xofInto(out);
922
+ }
923
+ randomBytes(length) {
924
+ return this.xof(length);
925
+ }
926
+ clean() {
927
+ // clean() mutates live sponge state just like randomBytes(),
928
+ // so destroyed instances must reject it.
929
+ aexists(this, false);
930
+ if (this.rate < 1600 / 2 + 1)
931
+ throw new Error('rate is too low to use .forget()');
932
+ this.keccak();
933
+ for (let i = 0; i < this.blockLen; i++)
934
+ this.state[i] = 0;
935
+ this.pos = this.blockLen;
936
+ this.keccak();
937
+ this.posOut = this.blockLen;
938
+ }
939
+ // Keccak cloning includes `posOut`, which preserves the PRG's current output phase.
940
+ _cloneInto(to) {
941
+ const { rate } = this;
942
+ to ||= new _KeccakPRG(1600 - rate);
943
+ super._cloneInto(to);
944
+ to.rate = rate;
945
+ to.entropyAdded = this.entropyAdded;
946
+ return to;
947
+ }
948
+ clone() {
949
+ return this._cloneInto();
950
+ }
951
+ }
952
+ /**
953
+ * KeccakPRG: pseudo-random generator based on Keccak.
954
+ * See {@link https://keccak.team/files/CSF-0.1.pdf}.
955
+ * Fresh instances reject output until `.addEntropy()` has been called. With no
956
+ * argument, `addEntropy()` obtains 32 bytes from the platform CSPRNG; callers
957
+ * may instead supply their own non-empty entropy bytes.
958
+ * @param capacity - sponge capacity in bits. Accepted values are those that
959
+ * keep `rho = 1598 - capacity` byte-aligned; the default `254` is chosen
960
+ * because it satisfies that duplex layout while leaving a wide byte-aligned
961
+ * rate.
962
+ * @returns PRG instance backed by a Keccak sponge.
963
+ * @example
964
+ * Create a Keccak-based pseudorandom generator and read bytes from it.
965
+ * ```ts
966
+ * import { keccakprg } from '@noble/hashes/sha3-addons.js';
967
+ *
968
+ * const prg = keccakprg(254);
969
+ * prg.addEntropy();
970
+ * prg.randomBytes(8);
971
+ * ```
972
+ */
973
+ export const keccakprg = (capacity = 254) => new _KeccakPRG(capacity);