toolcraft 0.0.749 → 0.0.750

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