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,978 @@
1
+ /**
2
+ * Utilities for hex, bytes, CSPRNG.
3
+ * @module
4
+ */
5
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
6
+ /**
7
+ * Bytes API type helpers for old + new TypeScript.
8
+ *
9
+ * TS 5.6 has `Uint8Array`, while TS 5.9+ made it generic `Uint8Array<ArrayBuffer>`.
10
+ * We can't use specific return type, because TS 5.6 will error.
11
+ * We can't use generic return type, because most TS 5.9 software will expect specific type.
12
+ *
13
+ * Maps typed-array input leaves to broad forms.
14
+ * These are compatibility adapters, not ownership guarantees.
15
+ *
16
+ * - `TArg` keeps byte inputs broad.
17
+ * - `TRet` marks byte outputs for TS 5.6 and TS 5.9+ compatibility.
18
+ */
19
+ export type TypedArg<T> = T extends BigInt64Array
20
+ ? BigInt64Array
21
+ : T extends BigUint64Array
22
+ ? BigUint64Array
23
+ : T extends Float32Array
24
+ ? Float32Array
25
+ : T extends Float64Array
26
+ ? Float64Array
27
+ : T extends Int16Array
28
+ ? Int16Array
29
+ : T extends Int32Array
30
+ ? Int32Array
31
+ : T extends Int8Array
32
+ ? Int8Array
33
+ : T extends Uint16Array
34
+ ? Uint16Array
35
+ : T extends Uint32Array
36
+ ? Uint32Array
37
+ : T extends Uint8ClampedArray
38
+ ? Uint8ClampedArray
39
+ : T extends Uint8Array
40
+ ? Uint8Array
41
+ : never;
42
+ /** Maps typed-array output leaves to narrow TS-compatible forms. */
43
+ export type TypedRet<T> = T extends BigInt64Array
44
+ ? ReturnType<typeof BigInt64Array.of>
45
+ : T extends BigUint64Array
46
+ ? ReturnType<typeof BigUint64Array.of>
47
+ : T extends Float32Array
48
+ ? ReturnType<typeof Float32Array.of>
49
+ : T extends Float64Array
50
+ ? ReturnType<typeof Float64Array.of>
51
+ : T extends Int16Array
52
+ ? ReturnType<typeof Int16Array.of>
53
+ : T extends Int32Array
54
+ ? ReturnType<typeof Int32Array.of>
55
+ : T extends Int8Array
56
+ ? ReturnType<typeof Int8Array.of>
57
+ : T extends Uint16Array
58
+ ? ReturnType<typeof Uint16Array.of>
59
+ : T extends Uint32Array
60
+ ? ReturnType<typeof Uint32Array.of>
61
+ : T extends Uint8ClampedArray
62
+ ? ReturnType<typeof Uint8ClampedArray.of>
63
+ : T extends Uint8Array
64
+ ? ReturnType<typeof Uint8Array.of>
65
+ : never;
66
+ /** Recursively adapts byte-carrying API input types. See {@link TypedArg}. */
67
+ export type TArg<T> =
68
+ | T
69
+ | ([TypedArg<T>] extends [never]
70
+ ? T extends (...args: infer A) => infer R
71
+ ? ((...args: { [K in keyof A]: TRet<A[K]> }) => TArg<R>) & {
72
+ [K in keyof T]: T[K] extends (...args: any) => any ? T[K] : TArg<T[K]>;
73
+ }
74
+ : T extends [infer A, ...infer R]
75
+ ? [TArg<A>, ...{ [K in keyof R]: TArg<R[K]> }]
76
+ : T extends readonly [infer A, ...infer R]
77
+ ? readonly [TArg<A>, ...{ [K in keyof R]: TArg<R[K]> }]
78
+ : T extends (infer A)[]
79
+ ? TArg<A>[]
80
+ : T extends readonly (infer A)[]
81
+ ? readonly TArg<A>[]
82
+ : T extends Promise<infer A>
83
+ ? Promise<TArg<A>>
84
+ : T extends object
85
+ ? { [K in keyof T]: TArg<T[K]> }
86
+ : T
87
+ : TypedArg<T>);
88
+ /** Recursively adapts byte-carrying API output types. See {@link TypedArg}. */
89
+ export type TRet<T> = T extends unknown
90
+ ? T &
91
+ ([TypedRet<T>] extends [never]
92
+ ? T extends (...args: infer A) => infer R
93
+ ? ((...args: { [K in keyof A]: TArg<A[K]> }) => TRet<R>) & {
94
+ [K in keyof T]: T[K] extends (...args: any) => any ? T[K] : TRet<T[K]>;
95
+ }
96
+ : T extends [infer A, ...infer R]
97
+ ? [TRet<A>, ...{ [K in keyof R]: TRet<R[K]> }]
98
+ : T extends readonly [infer A, ...infer R]
99
+ ? readonly [TRet<A>, ...{ [K in keyof R]: TRet<R[K]> }]
100
+ : T extends (infer A)[]
101
+ ? TRet<A>[]
102
+ : T extends readonly (infer A)[]
103
+ ? readonly TRet<A>[]
104
+ : T extends Promise<infer A>
105
+ ? Promise<TRet<A>>
106
+ : T extends object
107
+ ? { [K in keyof T]: TRet<T[K]> }
108
+ : T
109
+ : TypedRet<T>)
110
+ : never;
111
+ /**
112
+ * Checks if something is Uint8Array. Be careful: nodejs Buffer will return true.
113
+ * @param a - value to test
114
+ * @returns `true` when the value is a Uint8Array-compatible view.
115
+ * @example
116
+ * Check whether a value is a Uint8Array-compatible view.
117
+ * ```ts
118
+ * isBytes(new Uint8Array([1, 2, 3]));
119
+ * ```
120
+ */
121
+ export function isBytes(a: unknown): a is Uint8Array {
122
+ // Plain `instanceof Uint8Array` is too strict for some Buffer / proxy / cross-realm cases.
123
+ // The fallback still requires a real ArrayBuffer view, so plain
124
+ // JSON-deserialized `{ constructor: ... }` spoofing is rejected, and
125
+ // `BYTES_PER_ELEMENT === 1` keeps the fallback on byte-oriented views.
126
+ return (
127
+ a instanceof Uint8Array ||
128
+ (ArrayBuffer.isView(a) &&
129
+ a.constructor.name === 'Uint8Array' &&
130
+ 'BYTES_PER_ELEMENT' in a &&
131
+ a.BYTES_PER_ELEMENT === 1)
132
+ );
133
+ }
134
+
135
+ // Shared error-message prefix builder. Only called on throw paths, so assert
136
+ // success paths never pay for the string concatenation.
137
+ const atitle = (title: string): string => (title ? `"${title}" ` : '');
138
+
139
+ /**
140
+ * Asserts something is a non-negative integer.
141
+ * @param n - number to validate
142
+ * @param title - label included in thrown errors
143
+ * @returns The validated number.
144
+ * @throws On wrong argument types. {@link TypeError}
145
+ * @throws On wrong argument ranges or values. {@link RangeError}
146
+ * @example
147
+ * Validate a non-negative integer option.
148
+ * ```ts
149
+ * anumber(32, 'length');
150
+ * ```
151
+ */
152
+ export function anumber(n: number, title: string = ''): number {
153
+ if (typeof n !== 'number')
154
+ throw new TypeError(atitle(title) + 'expected number, got ' + typeof n);
155
+ if (!Number.isSafeInteger(n) || n < 0)
156
+ throw new RangeError(atitle(title) + 'expected integer >= 0, got ' + n);
157
+ return n;
158
+ }
159
+
160
+ /**
161
+ * Asserts something is a boolean.
162
+ * @param value - value to validate
163
+ * @param title - label included in thrown errors
164
+ * @returns The validated boolean.
165
+ * @throws On wrong argument types. {@link TypeError}
166
+ * @example
167
+ * Validate a boolean option.
168
+ * ```ts
169
+ * abool(true, 'enableXOF');
170
+ * ```
171
+ */
172
+ export function abool(value: boolean, title: string = ''): boolean {
173
+ if (typeof value !== 'boolean')
174
+ throw new TypeError(atitle(title) + 'expected boolean, got type=' + typeof value);
175
+ return value;
176
+ }
177
+
178
+ /**
179
+ * Asserts something is Uint8Array.
180
+ * @param value - value to validate
181
+ * @param length - optional exact length constraint
182
+ * @param title - label included in thrown errors
183
+ * @returns The validated byte array.
184
+ * @throws On wrong argument types. {@link TypeError}
185
+ * @throws On wrong argument ranges or values. {@link RangeError}
186
+ * @example
187
+ * Validate that a value is a byte array.
188
+ * ```ts
189
+ * abytes(new Uint8Array([1, 2, 3]));
190
+ * ```
191
+ */
192
+ export function abytes(
193
+ value: TArg<Uint8Array>,
194
+ length?: number,
195
+ title: string = ''
196
+ ): TRet<Uint8Array> {
197
+ // Success path first: this runs at the start of every update() / digestInto(), and the
198
+ // common `abytes(data)` form must not pay for length handling it does not use.
199
+ if (isBytes(value) && (length === undefined || value.length === length))
200
+ return value as TRet<Uint8Array>;
201
+ // Error path: recompute freely to build the exact message.
202
+ if (length !== undefined) anumber(length, 'length');
203
+ const bytes = isBytes(value);
204
+ const ofLen = length !== undefined ? ` of length ${length}` : '';
205
+ const got = bytes ? `length=${value.length}` : `type=${typeof value}`;
206
+ const message = atitle(title) + 'expected Uint8Array' + ofLen + ', got ' + got;
207
+ if (!bytes) throw new TypeError(message);
208
+ throw new RangeError(message);
209
+ }
210
+
211
+ /**
212
+ * Copies bytes into a fresh Uint8Array.
213
+ * Buffer-style slices can alias the same backing store, so callers that need ownership should copy.
214
+ * @param bytes - source bytes to clone
215
+ * @returns Freshly allocated copy of `bytes`.
216
+ * @throws On wrong argument types. {@link TypeError}
217
+ * @example
218
+ * Clone a byte array before mutating it.
219
+ * ```ts
220
+ * const copy = copyBytes(new Uint8Array([1, 2, 3]));
221
+ * ```
222
+ */
223
+ export function copyBytes(bytes: TArg<Uint8Array>): TRet<Uint8Array> {
224
+ // `Uint8Array.from(...)` would also accept arrays / other typed arrays. Keep this helper strict
225
+ // because callers use it at byte-validation boundaries before mutating the detached copy.
226
+ return Uint8Array.from(abytes(bytes)) as TRet<Uint8Array>;
227
+ }
228
+
229
+ /**
230
+ * Asserts something is a wrapped hash constructor.
231
+ * @param h - hash constructor to validate
232
+ * @throws On wrong argument types or invalid hash wrapper shape. {@link TypeError}
233
+ * @throws On invalid hash metadata ranges or values. {@link RangeError}
234
+ * @throws If the hash metadata allows empty outputs or block sizes. {@link Error}
235
+ * @example
236
+ * Validate a callable hash wrapper.
237
+ * ```ts
238
+ * import { ahash } from '@noble/hashes/utils.js';
239
+ * import { sha256 } from '@noble/hashes/sha2.js';
240
+ * ahash(sha256);
241
+ * ```
242
+ */
243
+ export function ahash(h: TArg<CHash>): void {
244
+ if (typeof h !== 'function' || typeof h.create !== 'function')
245
+ throw new TypeError('expected hash wrapped by utils.createHasher');
246
+ anumber(h.outputLen);
247
+ anumber(h.blockLen);
248
+ // HMAC and KDF callers treat these as real byte lengths; allowing zero lets fake wrappers pass
249
+ // validation and can produce empty outputs instead of failing fast.
250
+ if (h.outputLen < 1 || h.blockLen < 1) throw new Error('hash blockLen / outputLen must be >= 1');
251
+ }
252
+
253
+ const aobject = (value: Record<string, any>, label: string) => {
254
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
255
+ throw new TypeError(
256
+ (label === 'object' ? '' : `"${label}" `) + 'expected object, got type=' + typeof value
257
+ );
258
+ };
259
+
260
+ const aopts = (value: Record<string, any>, label: string) => {
261
+ aobject(value, label);
262
+ const proto = Object.getPrototypeOf(value);
263
+ if (proto !== Object.prototype && proto !== null)
264
+ throw new TypeError(`"${label}" expected plain object`);
265
+ // Object.assign() treats an own "__proto__" source key as a write to the target's legacy
266
+ // prototype setter. Reject it before merging so inherited option values cannot be injected.
267
+ if (Object.hasOwn(value, '__proto__')) throw new TypeError(`"${label}.__proto__" is not allowed`);
268
+ };
269
+
270
+ /**
271
+ * Asserts a hash instance has not been destroyed or finished.
272
+ * @param instance - hash instance to validate
273
+ * @param checkFinished - whether to reject finalized instances
274
+ * @throws If the hash instance has already been destroyed or finalized. {@link Error}
275
+ * @example
276
+ * Validate that a hash instance is still usable.
277
+ * ```ts
278
+ * import { aexists } from '@noble/hashes/utils.js';
279
+ * import { sha256 } from '@noble/hashes/sha2.js';
280
+ * const hash = sha256.create();
281
+ * aexists(hash);
282
+ * ```
283
+ */
284
+ export function aexists(instance: any, checkFinished = true): void {
285
+ // Runs on every update()/digestInto(); the flags are library-owned booleans, so only their
286
+ // truthiness is checked - re-validating their type per call was pure hot-path overhead.
287
+ if (instance.destroyed) throw new Error('hash was destroyed');
288
+ if (checkFinished && instance.finished) throw new Error('digest() was already called');
289
+ }
290
+
291
+ /**
292
+ * Asserts output is a sufficiently-sized byte array.
293
+ * @param out - destination buffer
294
+ * @param instance - hash instance providing output length
295
+ * Oversized buffers are allowed; downstream code only promises to fill the first `outputLen` bytes.
296
+ * @throws On wrong argument types. {@link TypeError}
297
+ * @throws On wrong argument ranges or values. {@link RangeError}
298
+ * @example
299
+ * Validate a caller-provided digest buffer.
300
+ * ```ts
301
+ * import { aoutput } from '@noble/hashes/utils.js';
302
+ * import { sha256 } from '@noble/hashes/sha2.js';
303
+ * const hash = sha256.create();
304
+ * aoutput(new Uint8Array(hash.outputLen), hash);
305
+ * ```
306
+ */
307
+ export function aoutput(out: any, instance: any): void {
308
+ abytes(out, undefined, 'output');
309
+ // `outputLen` is a library-owned readonly number; the negated comparison keeps failing fast
310
+ // when it is missing/NaN (comparisons with undefined/NaN are false) without an anumber() call.
311
+ const min = instance.outputLen;
312
+ if (!(out.length >= min)) {
313
+ throw new RangeError('"output" expected length >= ' + min);
314
+ }
315
+ }
316
+
317
+ /** Generic type encompassing 8/16/32-bit typed arrays, but not 64-bit. */
318
+ // prettier-ignore
319
+ export type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |
320
+ Uint16Array | Int16Array | Uint32Array | Int32Array;
321
+
322
+ /**
323
+ * Casts a typed array view to Uint8Array.
324
+ * @param arr - source typed array
325
+ * @returns Uint8Array view over the same buffer.
326
+ * @example
327
+ * Reinterpret a typed array as bytes.
328
+ * ```ts
329
+ * u8(new Uint32Array([1, 2]));
330
+ * ```
331
+ */
332
+ export function u8(arr: TArg<TypedArray>): TRet<Uint8Array> {
333
+ return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength) as TRet<Uint8Array>;
334
+ }
335
+
336
+ /**
337
+ * Casts a typed array view to Uint32Array.
338
+ * `arr.byteOffset` must already be 4-byte aligned or the platform
339
+ * Uint32Array constructor will throw.
340
+ * @param arr - source typed array
341
+ * @returns Uint32Array view over the same buffer.
342
+ * @example
343
+ * Reinterpret a byte array as 32-bit words.
344
+ * ```ts
345
+ * u32(new Uint8Array(8));
346
+ * ```
347
+ */
348
+ export function u32(arr: TArg<TypedArray>): TRet<Uint32Array> {
349
+ return new Uint32Array(
350
+ arr.buffer,
351
+ arr.byteOffset,
352
+ Math.floor(arr.byteLength / 4)
353
+ ) as TRet<Uint32Array>;
354
+ }
355
+
356
+ /**
357
+ * Zeroizes typed arrays in place. Warning: JS provides no guarantees.
358
+ * @param arrays - arrays to overwrite with zeros
359
+ * @example
360
+ * Zeroize sensitive buffers in place.
361
+ * ```ts
362
+ * clean(new Uint8Array([1, 2, 3]));
363
+ * ```
364
+ */
365
+ export function clean(...arrays: TArg<TypedArray[]>): void {
366
+ for (let i = 0; i < arrays.length; i++) {
367
+ arrays[i].fill(0);
368
+ }
369
+ }
370
+
371
+ /**
372
+ * Creates a DataView for byte-level manipulation.
373
+ * @param arr - source typed array
374
+ * @returns DataView over the same buffer region.
375
+ * @example
376
+ * Create a DataView over an existing buffer.
377
+ * ```ts
378
+ * createView(new Uint8Array(4));
379
+ * ```
380
+ */
381
+ export function createView(arr: TArg<TypedArray>): DataView {
382
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
383
+ }
384
+
385
+ /**
386
+ * Rotate-right operation for uint32 values.
387
+ * @param word - source word
388
+ * @param shift - shift amount in bits
389
+ * @returns Rotated word.
390
+ * @example
391
+ * Rotate a 32-bit word to the right.
392
+ * ```ts
393
+ * rotr(0x12345678, 8);
394
+ * ```
395
+ */
396
+ export function rotr(word: number, shift: number): number {
397
+ return (word << (32 - shift)) | (word >>> shift);
398
+ }
399
+
400
+ /**
401
+ * Rotate-left operation for uint32 values.
402
+ * @param word - source word
403
+ * @param shift - shift amount in bits
404
+ * @returns Rotated word.
405
+ * @example
406
+ * Rotate a 32-bit word to the left.
407
+ * ```ts
408
+ * rotl(0x12345678, 8);
409
+ * ```
410
+ */
411
+ export function rotl(word: number, shift: number): number {
412
+ return (word << shift) | ((word >>> (32 - shift)) >>> 0);
413
+ }
414
+
415
+ /** Whether the current platform is little-endian. */
416
+ export const isLE: boolean = /* @__PURE__ */ (() =>
417
+ new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
418
+
419
+ /**
420
+ * Byte-swap operation for uint32 values.
421
+ * @param word - source word
422
+ * @returns Word with reversed byte order.
423
+ * @example
424
+ * Reverse the byte order of a 32-bit word.
425
+ * ```ts
426
+ * byteSwap(0x11223344);
427
+ * ```
428
+ */
429
+ export function byteSwap(word: number): number {
430
+ return (
431
+ ((word << 24) & 0xff000000) |
432
+ ((word << 8) & 0xff0000) |
433
+ ((word >>> 8) & 0xff00) |
434
+ ((word >>> 24) & 0xff)
435
+ );
436
+ }
437
+ /**
438
+ * Conditionally byte-swaps one 32-bit word on big-endian platforms.
439
+ * @param n - source word
440
+ * @returns Original or byte-swapped word depending on platform endianness.
441
+ * @example
442
+ * Normalize a 32-bit word for host endianness.
443
+ * ```ts
444
+ * swap8IfBE(0x11223344);
445
+ * ```
446
+ */
447
+ export const swap8IfBE: (n: number) => number = isLE
448
+ ? (n: number) => n
449
+ : (n: number) => byteSwap(n) >>> 0;
450
+
451
+ /**
452
+ * Byte-swaps every word of a Uint32Array in place.
453
+ * @param arr - array to mutate
454
+ * @returns The same array after mutation; callers pass live state arrays here.
455
+ * @example
456
+ * Reverse the byte order of every word in place.
457
+ * ```ts
458
+ * byteSwap32(new Uint32Array([0x11223344]));
459
+ * ```
460
+ */
461
+ export function byteSwap32(arr: TArg<Uint32Array>): TRet<Uint32Array> {
462
+ for (let i = 0; i < arr.length; i++) {
463
+ arr[i] = byteSwap(arr[i]);
464
+ }
465
+ return arr as TRet<Uint32Array>;
466
+ }
467
+
468
+ /**
469
+ * Conditionally byte-swaps a Uint32Array on big-endian platforms.
470
+ * @param u - array to normalize for host endianness
471
+ * @returns Original or byte-swapped array depending on platform endianness.
472
+ * On big-endian runtimes this mutates `u` in place via `byteSwap32(...)`.
473
+ * @example
474
+ * Normalize a word array for host endianness.
475
+ * ```ts
476
+ * swap32IfBE(new Uint32Array([0x11223344]));
477
+ * ```
478
+ */
479
+ export const swap32IfBE: (u: TArg<Uint32Array>) => TRet<Uint32Array> = isLE
480
+ ? (u: TArg<Uint32Array>) => u as TRet<Uint32Array>
481
+ : byteSwap32;
482
+
483
+ // Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex
484
+ const hasHexBuiltin: boolean = /* @__PURE__ */ (() =>
485
+ // @ts-ignore
486
+ typeof Uint8Array.from([]).toHex === 'function' && typeof Uint8Array.fromHex === 'function')();
487
+
488
+ // Array where index 0xf0 (240) is mapped to string 'f0'
489
+ const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) =>
490
+ i.toString(16).padStart(2, '0')
491
+ );
492
+
493
+ /**
494
+ * Convert byte array to hex string.
495
+ * Uses the built-in function when available and assumes it matches the tested
496
+ * fallback semantics.
497
+ * @param bytes - bytes to encode
498
+ * @returns Lowercase hexadecimal string.
499
+ * @throws On wrong argument types. {@link TypeError}
500
+ * @example
501
+ * Convert bytes to lowercase hexadecimal.
502
+ * ```ts
503
+ * bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])); // 'cafe0123'
504
+ * ```
505
+ */
506
+ export function bytesToHex(bytes: TArg<Uint8Array>): string {
507
+ abytes(bytes);
508
+ // @ts-ignore
509
+ if (hasHexBuiltin) return bytes.toHex();
510
+ // pre-caching improves the speed 6x
511
+ let hex = '';
512
+ for (let i = 0; i < bytes.length; i++) {
513
+ hex += hexes[bytes[i]];
514
+ }
515
+ return hex;
516
+ }
517
+
518
+ // Strict ASCII nibble parser: non-ASCII hex lookalikes are rejected as undefined.
519
+ // ASCII codes: '0'..'9' = 48..57, 'A'..'F' = 65..70, 'a'..'f' = 97..102.
520
+ // prettier-ignore
521
+ function asciiToBase16(ch: number): number | undefined {
522
+ return ch >= 48 && ch <= 57 ? ch - 48 // '2' => 50-48
523
+ : ch >= 65 && ch <= 70 ? ch - (65 - 10) // 'B' => 66-(65-10)
524
+ : ch >= 97 && ch <= 102 ? ch - (97 - 10) // 'b' => 98-(97-10)
525
+ : undefined;
526
+ }
527
+
528
+ /**
529
+ * Convert hex string to byte array. Uses built-in function, when available.
530
+ * @param hex - hexadecimal string to decode
531
+ * @returns Decoded bytes.
532
+ * @throws On wrong argument types. {@link TypeError}
533
+ * @throws On wrong argument ranges or values. {@link RangeError}
534
+ * @example
535
+ * Decode lowercase hexadecimal into bytes.
536
+ * ```ts
537
+ * hexToBytes('cafe0123'); // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
538
+ * ```
539
+ */
540
+ export function hexToBytes(hex: string): TRet<Uint8Array> {
541
+ if (typeof hex !== 'string') throw new TypeError('hex string expected, got ' + typeof hex);
542
+ if (hasHexBuiltin) {
543
+ try {
544
+ return (Uint8Array as any).fromHex(hex);
545
+ } catch (error) {
546
+ if (error instanceof SyntaxError) throw new RangeError(error.message);
547
+ throw error;
548
+ }
549
+ }
550
+ const hl = hex.length;
551
+ const al = hl / 2;
552
+ if (hl % 2) throw new RangeError('hex string expected, got unpadded hex of length ' + hl);
553
+ const array = new Uint8Array(al);
554
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
555
+ const n1 = asciiToBase16(hex.charCodeAt(hi)); // parse first char, multiply it by 16
556
+ const n2 = asciiToBase16(hex.charCodeAt(hi + 1)); // parse second char
557
+ if (n1 === undefined || n2 === undefined) {
558
+ const char = hex[hi] + hex[hi + 1];
559
+ throw new RangeError(
560
+ 'hex string expected, got non-hex character "' + char + '" at index ' + hi
561
+ );
562
+ }
563
+ array[ai] = n1 * 16 + n2; // example: 'A9' => 10*16 + 9
564
+ }
565
+ return array;
566
+ }
567
+
568
+ /**
569
+ * Yields to the host task scheduler so timers, I/O, and rendering can make progress.
570
+ * Uses the Web Scheduling API when available or `setTimeout` as a cross-platform fallback.
571
+ * Host-task yields are much slower than microtasks (roughly 1ms with the timer fallback), so
572
+ * async loops should use `asyncTick >= 10` to amortize scheduling overhead to about 10% while
573
+ * still allowing other event-loop work to proceed.
574
+ * @param onReject - optional cleanup invoked only if the host yield fails
575
+ * @example
576
+ * Yield to the next scheduler tick.
577
+ * ```ts
578
+ * await nextTick();
579
+ * ```
580
+ */
581
+ export function nextTick(onReject?: () => void): Promise<void> {
582
+ const host = globalThis as any;
583
+ if (typeof host.scheduler?.yield === 'function') {
584
+ const promise: Promise<void> = host.scheduler.yield();
585
+ // Keep the original scheduler rejection; this handler exists only for cleanup.
586
+ if (onReject) promise.catch(onReject);
587
+ return promise;
588
+ }
589
+ return new Promise((resolve) => host.setTimeout(resolve, 0));
590
+ }
591
+
592
+ /**
593
+ * Returns control to the host event loop every `tick` milliseconds to avoid blocking long loops.
594
+ * @param iters - number of loop iterations to run
595
+ * @param tick - maximum time slice in milliseconds
596
+ * @param cb - callback executed on each iteration
597
+ * @param onReject - optional cleanup invoked only if a host yield fails
598
+ * @throws On wrong argument types. {@link TypeError}
599
+ * @throws On wrong argument ranges or values. {@link RangeError}
600
+ * @example
601
+ * Run a loop that periodically yields back to the event loop.
602
+ * ```ts
603
+ * await asyncLoop(2, 0, () => {});
604
+ * ```
605
+ */
606
+ export async function asyncLoop(
607
+ iters: number,
608
+ tick: number,
609
+ cb: (i: number) => void,
610
+ onReject?: () => void
611
+ ): Promise<void> {
612
+ anumber(iters, 'iters');
613
+ anumber(tick, 'tick');
614
+ if (typeof cb !== 'function') throw new TypeError('callback must be a function');
615
+ // Callback is synchronous by contract; asyncLoop only yields between sync work windows.
616
+ let ts = Date.now();
617
+ for (let i = 0; i < iters; i++) {
618
+ cb(i);
619
+ // Date.now() is not monotonic, so in case if clock goes backwards we return return control too
620
+ const diff = Date.now() - ts;
621
+ if (diff >= 0 && diff < tick) continue;
622
+ await nextTick(onReject);
623
+ // Track only synchronous work time; scheduler delay after yielding is outside our budget.
624
+ ts = Date.now();
625
+ }
626
+ }
627
+
628
+ // Global symbols, but ts doesn't see them: https://github.com/microsoft/TypeScript/issues/31535
629
+ declare const TextEncoder: any;
630
+
631
+ /**
632
+ * Converts string to bytes using UTF8 encoding.
633
+ * Built-in doesn't validate input to be string: we do the check.
634
+ * Non-ASCII details are delegated to the platform `TextEncoder`.
635
+ * @param str - string to encode
636
+ * @returns UTF-8 encoded bytes.
637
+ * @throws On wrong argument types. {@link TypeError}
638
+ * @example
639
+ * Encode a string as UTF-8 bytes.
640
+ * ```ts
641
+ * utf8ToBytes('abc'); // Uint8Array.from([97, 98, 99])
642
+ * ```
643
+ */
644
+ export function utf8ToBytes(str: string): TRet<Uint8Array> {
645
+ if (typeof str !== 'string') throw new TypeError('string expected');
646
+ const encoded = new TextEncoder().encode(str);
647
+ try {
648
+ // Copy into the current realm for Firefox extension contexts. Callers that own the returned
649
+ // buffer can then wipe it independently of TextEncoder's temporary result.
650
+ return new Uint8Array(encoded) as TRet<Uint8Array>; // https://bugzil.la/1681809
651
+ } finally {
652
+ clean(encoded);
653
+ }
654
+ }
655
+
656
+ /** KDFs can accept string or Uint8Array for user convenience. */
657
+ export type KDFInput = string | Uint8Array;
658
+
659
+ /**
660
+ * Helper for KDFs: consumes Uint8Array or string.
661
+ * String inputs are UTF-8 encoded; byte-array inputs stay aliased to the caller buffer.
662
+ * @param data - user-provided KDF input
663
+ * @param errorTitle - label included in thrown errors
664
+ * @returns Byte representation of the input.
665
+ * @throws On wrong argument types. {@link TypeError}
666
+ * @example
667
+ * Normalize KDF input to bytes.
668
+ * ```ts
669
+ * kdfInputToBytes('password');
670
+ * ```
671
+ */
672
+ export function kdfInputToBytes(data: TArg<KDFInput>, errorTitle = ''): TRet<Uint8Array> {
673
+ if (typeof data === 'string') return utf8ToBytes(data);
674
+ return abytes(data, undefined, errorTitle);
675
+ }
676
+
677
+ /**
678
+ * Copies several Uint8Arrays into one.
679
+ * @param arrays - arrays to concatenate
680
+ * @returns Concatenated byte array.
681
+ * @throws On wrong argument types. {@link TypeError}
682
+ * @example
683
+ * Concatenate multiple byte arrays.
684
+ * ```ts
685
+ * concatBytes(new Uint8Array([1]), new Uint8Array([2]));
686
+ * ```
687
+ */
688
+ export function concatBytes(...arrays: TArg<Uint8Array[]>): TRet<Uint8Array> {
689
+ let sum = 0;
690
+ for (let i = 0; i < arrays.length; i++) {
691
+ const a = arrays[i];
692
+ abytes(a);
693
+ sum += a.length;
694
+ }
695
+ const res = new Uint8Array(sum);
696
+ for (let i = 0, pad = 0; i < arrays.length; i++) {
697
+ const a = arrays[i];
698
+ res.set(a, pad);
699
+ pad += a.length;
700
+ }
701
+ return res;
702
+ }
703
+
704
+ type EmptyObj = {};
705
+ /**
706
+ * Validates declared required and optional field types on a plain object.
707
+ * This walks field schemas and formats detailed errors, so avoid it on hot paths; use direct
708
+ * one-line guards such as `abytes()`, `abool()`, or `anumber()` instead.
709
+ * @param object - object to validate
710
+ * @param fields - map of required field names to expected types
711
+ * @param optFields - map of optional field names to expected types
712
+ * @param title - label included in thrown errors
713
+ * @throws On wrong argument types. {@link TypeError}
714
+ * @example
715
+ * Validate required and optional option fields.
716
+ * ```ts
717
+ * validateObject({ N: 1024, dkLen: 32 }, { N: 'number' }, { dkLen: 'number' });
718
+ * ```
719
+ */
720
+ export const validateObject = (
721
+ object: Record<string, any>,
722
+ fields: Record<string, string> = {},
723
+ optFields: Record<string, string> = {},
724
+ title = 'object'
725
+ ): void => {
726
+ aobject(object, title);
727
+ aobject(fields, 'fields');
728
+ aobject(optFields, 'optFields');
729
+ type Item = keyof typeof object;
730
+ function checkField(fieldName: Item, expectedType: string, isOpt: boolean) {
731
+ const label =
732
+ title === 'object' ? `param "${String(fieldName)}"` : `"${title}.${String(fieldName)}"`;
733
+ // Config fields must be explicit own properties. Optional inherited values are rejected too
734
+ // because callers keep reading the same options object after validation.
735
+ const val = object[fieldName];
736
+ // Runtime objects such as Field instances intentionally satisfy required method slots
737
+ // via their shared prototype.
738
+ if (
739
+ !Object.hasOwn(object, fieldName) &&
740
+ (isOpt ? val !== undefined : expectedType !== 'function')
741
+ ) {
742
+ throw new TypeError(`${label} is invalid: expected own property`);
743
+ }
744
+ if (isOpt && val === undefined) return;
745
+ const current = typeof val;
746
+ if (current !== expectedType || val === null)
747
+ throw new TypeError(`${label} is invalid: expected ${expectedType}, got ${current}`);
748
+ }
749
+ const iter = (f: typeof fields, isOpt: boolean) =>
750
+ Object.entries(f).forEach(([k, v]) => checkField(k, v, isOpt));
751
+ iter(fields, false);
752
+ iter(optFields, true);
753
+ };
754
+ /**
755
+ * Merges default options and passed options.
756
+ * @param defaults - base option object
757
+ * @param opts - user overrides
758
+ * @param title - label included in thrown override errors
759
+ * @returns Fresh merged option object with a null prototype.
760
+ * @throws On wrong argument types. {@link TypeError}
761
+ * @example
762
+ * Merge user overrides onto default options.
763
+ * ```ts
764
+ * checkOpts({ dkLen: 32 }, { asyncTick: 10 });
765
+ * ```
766
+ */
767
+ export function checkOpts<T1 extends EmptyObj, T2 extends EmptyObj>(
768
+ defaults: T1,
769
+ opts?: T2,
770
+ title = 'opts'
771
+ ): T1 & T2 {
772
+ aopts(defaults as Record<string, any>, 'defaults');
773
+ if (opts !== undefined) aopts(opts as Record<string, any>, title);
774
+ // Callers read optional fields directly, so omitted values must not fall through to ambient
775
+ // Object.prototype pollution (for example a forged `dkLen` changing SHAKE's default output).
776
+ const merged = Object.assign(Object.create(null), defaults, opts);
777
+ return merged as T1 & T2;
778
+ }
779
+
780
+ /** Common interface for all hash instances. */
781
+ export interface Hash<T> {
782
+ /** Bytes processed per compression block. */
783
+ blockLen: number;
784
+ /** Bytes produced by `digest()`. */
785
+ outputLen: number;
786
+ /** Whether the instance supports XOF-style variable-length output via `xof()` / `xofInto()`. */
787
+ canXOF: boolean;
788
+ /**
789
+ * Absorbs more message bytes into the running hash state.
790
+ * @param buf - message chunk to absorb
791
+ * @returns The same hash instance for chaining.
792
+ */
793
+ update(buf: TArg<Uint8Array>): this;
794
+ /**
795
+ * Finalizes the hash into a caller-provided buffer.
796
+ * @param buf - destination buffer
797
+ * @returns Nothing. Implementations write into `buf` in place.
798
+ */
799
+ digestInto(buf: TArg<Uint8Array>): void;
800
+ /**
801
+ * Finalizes the hash and returns a freshly allocated digest.
802
+ * @returns Digest bytes.
803
+ */
804
+ digest(): TRet<Uint8Array>;
805
+ /** Wipes internal state and makes the instance unusable. */
806
+ destroy(): void;
807
+ /**
808
+ * Copies the current hash state into an existing or new instance.
809
+ * @param to - Optional destination instance to reuse.
810
+ * @returns Cloned hash state.
811
+ */
812
+ _cloneInto(to?: T): T;
813
+ /**
814
+ * Creates an independent copy of the current hash state.
815
+ * @returns Cloned hash instance.
816
+ */
817
+ clone(): T;
818
+ }
819
+
820
+ /**
821
+ * The pseudorandom number generator doesn't wipe current state:
822
+ * instead, it generates new one based on previous state + entropy.
823
+ * Not reseed/rekey, since AES CTR DRBG does rekey on each randomBytes,
824
+ * which is in fact `reseed`, since it changes counter too.
825
+ */
826
+ export interface PRG {
827
+ /**
828
+ * Mixes fresh entropy into the current generator state.
829
+ * @param seed - Non-empty entropy bytes to absorb. When omitted, the implementation uses its
830
+ * system RNG.
831
+ */
832
+ addEntropy(seed?: TArg<Uint8Array>): void;
833
+ /**
834
+ * Produces a requested number of pseudorandom bytes.
835
+ * @param bytesLength - Number of bytes to generate.
836
+ * @returns Random byte array.
837
+ */
838
+ randomBytes(bytesLength: number): TRet<Uint8Array>;
839
+ /** Destroys the generator state. */
840
+ clean(): void;
841
+ }
842
+
843
+ /**
844
+ * XOF: streaming API to read digest in chunks.
845
+ * Same as 'squeeze' in keccak/k12 and 'seek' in blake3, but more generic name.
846
+ * When hash used in XOF mode it is up to user to call '.destroy' afterwards, since we cannot
847
+ * destroy state, next call can require more bytes.
848
+ */
849
+ export type HashXOF<T extends Hash<T>> = Hash<T> & {
850
+ /**
851
+ * Reads more bytes from the XOF stream.
852
+ * @param bytes - number of bytes to read
853
+ * @returns Requested digest bytes.
854
+ */
855
+ xof(bytes: number): TRet<Uint8Array>;
856
+ /**
857
+ * Reads more bytes from the XOF stream into a caller-provided buffer.
858
+ * @param buf - destination buffer
859
+ * @returns Filled output buffer.
860
+ */
861
+ xofInto(buf: TArg<Uint8Array>): TRet<Uint8Array>;
862
+ };
863
+
864
+ /** Hash constructor or factory type. */
865
+ export type HasherCons<T, Opts = undefined> = Opts extends undefined ? () => T : (opts?: Opts) => T;
866
+ /** Optional hash metadata. */
867
+ export type HashInfo = {
868
+ /** DER-encoded object identifier bytes for the hash algorithm. */
869
+ oid?: TRet<Uint8Array>;
870
+ };
871
+ /** Callable hash function type. */
872
+ export type CHash<T extends Hash<T> = Hash<any>, Opts = undefined> = {
873
+ /** Digest size in bytes. */
874
+ outputLen: number;
875
+ /** Input block size in bytes. */
876
+ blockLen: number;
877
+ /** Whether `.create()` returns a hash instance that can be used as an XOF stream. */
878
+ canXOF: boolean;
879
+ } & HashInfo &
880
+ (Opts extends undefined
881
+ ? {
882
+ (msg: TArg<Uint8Array>): TRet<Uint8Array>;
883
+ create(): T;
884
+ }
885
+ : {
886
+ (msg: TArg<Uint8Array>, opts?: TArg<Opts>): TRet<Uint8Array>;
887
+ create(opts?: Opts): T;
888
+ });
889
+ /** Callable extendable-output hash function type. */
890
+ export type CHashXOF<T extends HashXOF<T> = HashXOF<any>, Opts = undefined> = CHash<T, Opts>;
891
+
892
+ /**
893
+ * Creates a callable hash function from a stateful class constructor.
894
+ * @param hashCons - hash constructor or factory
895
+ * @param info - optional metadata such as DER OID
896
+ * @returns Frozen callable hash wrapper with `.create()`.
897
+ * Wrapper construction eagerly calls `hashCons(undefined)` once to read
898
+ * `outputLen` / `blockLen`, so constructor side effects happen at module
899
+ * init time.
900
+ * @throws On wrong argument types. {@link TypeError}
901
+ * @example
902
+ * Wrap a stateful hash constructor into a callable helper.
903
+ * ```ts
904
+ * import { createHasher } from '@noble/hashes/utils.js';
905
+ * import { sha256 } from '@noble/hashes/sha2.js';
906
+ * const wrapped = createHasher(sha256.create, { oid: sha256.oid });
907
+ * wrapped(new Uint8Array([1]));
908
+ * ```
909
+ */
910
+ export function createHasher<T extends Hash<T>, Opts = undefined>(
911
+ hashCons: HasherCons<T, Opts>,
912
+ info: TArg<HashInfo> = {}
913
+ ): TRet<CHash<T, Opts>> {
914
+ if (typeof hashCons !== 'function')
915
+ throw new TypeError('"hashCons" expected function, got type=' + typeof hashCons);
916
+ info = checkOpts({}, info, 'info') as HashInfo;
917
+ const hashC: any = (msg: TArg<Uint8Array>, opts?: TArg<Opts>) =>
918
+ hashCons(opts as Opts)
919
+ .update(msg)
920
+ .digest();
921
+ const tmp = hashCons(undefined);
922
+ hashC.outputLen = tmp.outputLen;
923
+ hashC.blockLen = tmp.blockLen;
924
+ hashC.canXOF = tmp.canXOF;
925
+ hashC.create = (opts?: Opts) => hashCons(opts);
926
+ Object.assign(hashC, info);
927
+ return Object.freeze(hashC) as TRet<CHash<T, Opts>>;
928
+ }
929
+
930
+ /**
931
+ * Cryptographically secure PRNG backed by `crypto.getRandomValues`.
932
+ * @param bytesLength - number of random bytes to generate
933
+ * @returns Random bytes.
934
+ * The platform `getRandomValues()` implementation still defines any
935
+ * single-call length cap, and this helper rejects oversize requests
936
+ * with a stable library `RangeError` instead of host-specific errors.
937
+ * @throws On wrong argument types. {@link TypeError}
938
+ * @throws On wrong argument ranges or values. {@link RangeError}
939
+ * @throws If the current runtime does not provide `crypto.getRandomValues`. {@link Error}
940
+ * @example
941
+ * Generate a fresh random key or nonce.
942
+ * ```ts
943
+ * const key = randomBytes(16);
944
+ * ```
945
+ */
946
+ export function randomBytes(bytesLength = 32): TRet<Uint8Array> {
947
+ // Match the repo's other length-taking helpers instead of relying on Uint8Array coercion.
948
+ anumber(bytesLength, 'bytesLength');
949
+ const cr = typeof globalThis === 'object' ? (globalThis as any).crypto : null;
950
+ if (typeof cr?.getRandomValues !== 'function')
951
+ throw new Error('crypto.getRandomValues must be defined');
952
+ // Web Cryptography API Level 2 §10.1.1:
953
+ // if `byteLength > 65536`, throw `QuotaExceededError`.
954
+ // Keep the guard explicit so callers can see the quota in code
955
+ // instead of discovering it by reading the spec or host errors.
956
+ // This wrapper surfaces the same quota as a stable library RangeError.
957
+ if (bytesLength > 65536)
958
+ throw new RangeError(`"bytesLength" expected <= 65536, got ${bytesLength}`);
959
+ return cr.getRandomValues(new Uint8Array(bytesLength));
960
+ }
961
+
962
+ /**
963
+ * Creates OID metadata for NIST hashes with prefix `06 09 60 86 48 01 65 03 04 02`.
964
+ * @param suffix - final OID byte for the selected hash.
965
+ * The helper accepts any byte even though only the documented NIST hash
966
+ * suffixes are meaningful downstream.
967
+ * @returns Object containing the DER-encoded OID.
968
+ * @example
969
+ * Build OID metadata for a NIST hash.
970
+ * ```ts
971
+ * oidNist(0x01);
972
+ * ```
973
+ */
974
+ export const oidNist = (suffix: number): TRet<Required<HashInfo>> => ({
975
+ // Current NIST hashAlgs suffixes used here fit in one DER subidentifier octet.
976
+ // Larger suffix values would need base-128 OID encoding and a different length byte.
977
+ oid: Uint8Array.from([0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, suffix]),
978
+ });