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.
- package/composition.json +23 -3
- package/dist/composition.json +23 -3
- package/dist/human-in-loop/approvals-commands.d.ts +1 -1
- package/dist/index.d.ts +1 -262
- package/dist/index.js +1 -573
- package/dist/runtime-platform.d.ts +2 -0
- package/dist/runtime-platform.js +2 -0
- package/dist/runtime-platform.workerd.d.ts +3 -0
- package/dist/runtime-platform.workerd.js +10 -0
- package/dist/runtime.d.ts +262 -0
- package/dist/runtime.js +576 -0
- package/node_modules/@noble/hashes/LICENSE +21 -0
- package/node_modules/@noble/hashes/README.md +478 -0
- package/node_modules/@noble/hashes/_blake.d.ts +20 -0
- package/node_modules/@noble/hashes/_blake.js +59 -0
- package/node_modules/@noble/hashes/_md.d.ts +95 -0
- package/node_modules/@noble/hashes/_md.js +209 -0
- package/node_modules/@noble/hashes/_u64.d.ts +36 -0
- package/node_modules/@noble/hashes/_u64.js +77 -0
- package/node_modules/@noble/hashes/argon2.d.ts +148 -0
- package/node_modules/@noble/hashes/argon2.js +577 -0
- package/node_modules/@noble/hashes/blake1.d.ts +162 -0
- package/node_modules/@noble/hashes/blake1.js +630 -0
- package/node_modules/@noble/hashes/blake2.d.ts +203 -0
- package/node_modules/@noble/hashes/blake2.js +573 -0
- package/node_modules/@noble/hashes/blake3.d.ts +68 -0
- package/node_modules/@noble/hashes/blake3.js +310 -0
- package/node_modules/@noble/hashes/eskdf.d.ts +91 -0
- package/node_modules/@noble/hashes/eskdf.js +225 -0
- package/node_modules/@noble/hashes/hkdf.d.ts +70 -0
- package/node_modules/@noble/hashes/hkdf.js +152 -0
- package/node_modules/@noble/hashes/hmac.d.ts +50 -0
- package/node_modules/@noble/hashes/hmac.js +93 -0
- package/node_modules/@noble/hashes/index.d.ts +1 -0
- package/node_modules/@noble/hashes/index.js +34 -0
- package/node_modules/@noble/hashes/legacy.d.ts +107 -0
- package/node_modules/@noble/hashes/legacy.js +348 -0
- package/node_modules/@noble/hashes/package.json +91 -0
- package/node_modules/@noble/hashes/pbkdf2.d.ts +66 -0
- package/node_modules/@noble/hashes/pbkdf2.js +176 -0
- package/node_modules/@noble/hashes/scrypt.d.ts +98 -0
- package/node_modules/@noble/hashes/scrypt.js +304 -0
- package/node_modules/@noble/hashes/sha2.d.ts +176 -0
- package/node_modules/@noble/hashes/sha2.js +446 -0
- package/node_modules/@noble/hashes/sha3-addons.d.ts +533 -0
- package/node_modules/@noble/hashes/sha3-addons.js +973 -0
- package/node_modules/@noble/hashes/sha3.d.ts +208 -0
- package/node_modules/@noble/hashes/sha3.js +475 -0
- package/node_modules/@noble/hashes/src/_blake.ts +67 -0
- package/node_modules/@noble/hashes/src/_md.ts +227 -0
- package/node_modules/@noble/hashes/src/_u64.ts +111 -0
- package/node_modules/@noble/hashes/src/argon2.ts +693 -0
- package/node_modules/@noble/hashes/src/blake1.ts +677 -0
- package/node_modules/@noble/hashes/src/blake2.ts +648 -0
- package/node_modules/@noble/hashes/src/blake3.ts +344 -0
- package/node_modules/@noble/hashes/src/eskdf.ts +265 -0
- package/node_modules/@noble/hashes/src/hkdf.ts +161 -0
- package/node_modules/@noble/hashes/src/hmac.ts +130 -0
- package/node_modules/@noble/hashes/src/index.ts +33 -0
- package/node_modules/@noble/hashes/src/legacy.ts +361 -0
- package/node_modules/@noble/hashes/src/pbkdf2.ts +219 -0
- package/node_modules/@noble/hashes/src/scrypt.ts +375 -0
- package/node_modules/@noble/hashes/src/sha2.ts +486 -0
- package/node_modules/@noble/hashes/src/sha3-addons.ts +1157 -0
- package/node_modules/@noble/hashes/src/sha3.ts +525 -0
- package/node_modules/@noble/hashes/src/utils.ts +978 -0
- package/node_modules/@noble/hashes/src/webcrypto.ts +283 -0
- package/node_modules/@noble/hashes/utils.d.ts +560 -0
- package/node_modules/@noble/hashes/utils.js +687 -0
- package/node_modules/@noble/hashes/webcrypto.d.ts +121 -0
- package/node_modules/@noble/hashes/webcrypto.js +228 -0
- package/node_modules/@poe-code/agent-mcp-config/dist/apply.js +23 -9
- package/node_modules/@poe-code/config-mutations/README.md +2 -0
- package/node_modules/@poe-code/config-mutations/dist/execution/apply-mutation.js +4 -5
- package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.d.ts +3 -4
- package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.js +3 -3
- package/node_modules/@poe-code/config-mutations/dist/template/render.js +1 -1
- package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.d.ts +2 -2
- package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.js +3 -6
- package/node_modules/@poe-code/config-mutations/dist/types.d.ts +4 -2
- package/node_modules/@poe-code/process-runner/README.md +2 -1
- package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.d.ts +1 -0
- package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.js +1 -0
- package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.workerd.d.ts +2 -0
- package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.workerd.js +1 -0
- package/node_modules/@poe-code/process-runner/dist/types.d.ts +1 -1
- package/node_modules/@poe-code/process-runner/dist/workspace-transfer.d.ts +6 -5
- package/node_modules/@poe-code/process-runner/dist/workspace-transfer.js +67 -29
- package/node_modules/@poe-code/process-runner/package.json +13 -0
- package/node_modules/@poe-code/safe-fs/LICENSE +21 -0
- package/node_modules/@poe-code/safe-fs/PROVENANCE.json +428 -0
- package/node_modules/@poe-code/safe-fs/README.md +411 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/confinement.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/confinement.js +171 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/filesystem.d.ts +93 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/filesystem.js +453 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/index.d.ts +7 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/index.js +19 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/stats.d.ts +4 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/stats.js +37 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/types.d.ts +81 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/types.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/values.d.ts +6 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/values.js +65 -0
- package/node_modules/@poe-code/safe-fs/dist/config/memory.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/config/memory.js +7 -0
- package/node_modules/@poe-code/safe-fs/dist/config/real.d.ts +5 -0
- package/node_modules/@poe-code/safe-fs/dist/config/real.js +16 -0
- package/node_modules/@poe-code/safe-fs/dist/config/registry.d.ts +2 -0
- package/node_modules/@poe-code/safe-fs/dist/config/registry.js +15 -0
- package/node_modules/@poe-code/safe-fs/dist/config.d.ts +15 -0
- package/node_modules/@poe-code/safe-fs/dist/config.js +46 -0
- package/node_modules/@poe-code/safe-fs/dist/config.node.d.ts +2 -0
- package/node_modules/@poe-code/safe-fs/dist/config.node.js +11 -0
- package/node_modules/@poe-code/safe-fs/dist/config.portable.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/config.portable.js +9 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/abort.d.ts +5 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/abort.js +34 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/cleanup.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/cleanup.js +9 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/descriptor.d.ts +38 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/descriptor.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/errors.d.ts +53 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/errors.js +99 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/filesystem.d.ts +379 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/filesystem.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/index.d.ts +6 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/index.js +6 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/io.d.ts +12 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/io.js +321 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/object.d.ts +134 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/object.js +97 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/path.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/path.js +2 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/portable-path.d.ts +21 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/portable-path.js +78 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/virtual-path.d.ts +15 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/virtual-path.js +162 -0
- package/node_modules/@poe-code/safe-fs/dist/core.d.ts +19 -0
- package/node_modules/@poe-code/safe-fs/dist/core.js +17 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/capabilities.d.ts +10 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/capabilities.js +216 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/conditional-chmod.d.ts +7 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/conditional-chmod.js +19 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/descriptor.d.ts +21 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/descriptor.js +279 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/devices/index.d.ts +59 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/devices/index.js +875 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/devices/path.d.ts +7 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/devices/path.js +250 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/devices/stream.d.ts +6 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/devices/stream.js +136 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/directory-admission.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/directory-admission.js +14 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/atomic-view.d.ts +11 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/atomic-view.js +13 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/index.d.ts +186 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/index.js +3771 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/ledger.d.ts +26 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/ledger.js +96 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/limits.d.ts +13 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/limits.js +26 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/missing-target.d.ts +15 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/missing-target.js +144 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/mount/comparison.d.ts +19 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/mount/comparison.js +118 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/mount/identity.d.ts +6 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/mount/identity.js +29 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/mount/index.d.ts +74 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/mount/index.js +1291 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/object-authority.d.ts +27 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/object-authority.js +287 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/object-publication/index.d.ts +45 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/object-publication/index.js +531 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/overlay/index.d.ts +87 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/overlay/index.js +1185 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/overlay/memory-publication.d.ts +42 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/overlay/memory-publication.js +558 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/path-namespace.d.ts +4 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/path-namespace.js +63 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/quota/index.d.ts +12 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/quota/index.js +520 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/readonly/index.d.ts +37 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/readonly/index.js +208 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/real/allocation.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/real/allocation.js +8 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/real/index.d.ts +105 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/real/index.js +1259 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/authority.d.ts +7 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/authority.js +38 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/filesystem.d.ts +130 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/filesystem.js +1137 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/bytes.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/bytes.js +9 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/index.d.ts +2 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/index.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-fetch.d.ts +15 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-fetch.js +74 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-node.d.ts +4 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-node.js +111 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request.d.ts +17 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request.js +89 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/signature.d.ts +20 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/signature.js +76 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/transport.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/transport.js +478 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/types.d.ts +30 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/types.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/xml.d.ts +14 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/xml.js +192 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/index.d.ts +8 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/index.js +4 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/key-order.d.ts +2 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/key-order.js +11 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/manifest-admission.d.ts +8 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/manifest-admission.js +167 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/mock.d.ts +48 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/mock.js +249 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/namespace.d.ts +13 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/namespace.js +400 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/registry.d.ts +10 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/registry.js +73 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/transport.d.ts +103 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/transport.js +28 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/scoped.d.ts +19 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/scoped.js +663 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/staging-ancestry.d.ts +8 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/staging-ancestry.js +115 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/staging-cleanup.d.ts +5 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/staging-cleanup.js +63 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/index.d.ts +2 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/index.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/resource-id.d.ts +18 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/resource-id.js +109 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/webdav.d.ts +141 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/webdav.js +1377 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/xml.d.ts +15 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/xml.js +59 -0
- package/node_modules/@poe-code/safe-fs/dist/index.d.ts +25 -0
- package/node_modules/@poe-code/safe-fs/dist/index.js +21 -0
- package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/linux-x64-glibc.node +0 -0
- package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/loader.d.ts +5 -0
- package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/loader.mjs +120 -0
- package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/manifest.json +46 -0
- package/node_modules/@poe-code/safe-fs/dist/node/filesystem.d.ts +19 -0
- package/node_modules/@poe-code/safe-fs/dist/node/filesystem.js +30 -0
- package/node_modules/@poe-code/safe-fs/dist/node/host.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/node/host.js +78 -0
- package/node_modules/@poe-code/safe-fs/dist/node/index.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/node/index.js +2 -0
- package/node_modules/@poe-code/safe-fs/dist/node/native-seek-unavailable.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node/native-seek-unavailable.js +5 -0
- package/node_modules/@poe-code/safe-fs/dist/node/native-seek.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/node/native-seek.js +54 -0
- package/node_modules/@poe-code/safe-fs/dist/node/stats.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node/stats.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node/values.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node/values.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node-host.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node-host.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node-unavailable.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node-unavailable.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/package.json +29 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/browser-path.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/browser-path.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/browser.d.ts +26 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/browser.js +58 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/node-path.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/node-path.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/node.d.ts +26 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/node.js +64 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/transport-budget.d.ts +9 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/transport-budget.js +17 -0
- package/node_modules/@poe-code/safe-fs/dist/python/emscripten.d.ts +15 -0
- package/node_modules/@poe-code/safe-fs/dist/python/emscripten.js +357 -0
- package/node_modules/@poe-code/safe-fs/dist/python/filesystem.d.ts +51 -0
- package/node_modules/@poe-code/safe-fs/dist/python/filesystem.js +243 -0
- package/node_modules/@poe-code/safe-fs/dist/python/flags.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/python/flags.js +14 -0
- package/node_modules/@poe-code/safe-fs/dist/python/index.d.ts +9 -0
- package/node_modules/@poe-code/safe-fs/dist/python/index.js +5 -0
- package/node_modules/@poe-code/safe-fs/dist/python/native.d.ts +18 -0
- package/node_modules/@poe-code/safe-fs/dist/python/native.js +446 -0
- package/node_modules/@poe-code/safe-fs/dist/python/request.d.ts +2 -0
- package/node_modules/@poe-code/safe-fs/dist/python/request.js +61 -0
- package/node_modules/@poe-code/safe-fs/dist/python/stat.d.ts +8 -0
- package/node_modules/@poe-code/safe-fs/dist/python/stat.js +34 -0
- package/node_modules/@poe-code/safe-fs/dist/runtime-core.d.ts +27 -0
- package/node_modules/@poe-code/safe-fs/dist/runtime-core.js +57 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/atomic-filesystem.d.ts +16 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/atomic-filesystem.js +496 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/object-io-control.d.ts +23 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/object-io-control.js +39 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/object-io-metrics.d.ts +31 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/object-io-metrics.js +143 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/object-publication.d.ts +19 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/object-publication.js +209 -0
- package/node_modules/@poe-code/safe-fs/dist/xml.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/xml.js +1 -0
- package/node_modules/@poe-code/safe-fs/package.json +189 -0
- package/node_modules/@poe-code/task-list/README.md +2 -0
- package/node_modules/@poe-code/task-list/dist/backends/gh-issues-client.d.ts +1 -1
- package/node_modules/@poe-code/task-list/dist/backends/gh-issues-client.js +11 -4
- package/node_modules/@poe-code/task-list/dist/backends/markdown-dir.js +2 -2
- package/node_modules/@poe-code/task-list/dist/backends/utils.js +5 -7
- package/node_modules/@poe-code/task-list/dist/backends/yaml-file.js +1 -1
- package/node_modules/@poe-code/task-list/dist/default-host.d.ts +2 -0
- package/node_modules/@poe-code/task-list/dist/default-host.js +2 -0
- package/node_modules/@poe-code/task-list/dist/default-host.workerd.d.ts +4 -0
- package/node_modules/@poe-code/task-list/dist/default-host.workerd.js +6 -0
- package/node_modules/@poe-code/task-list/dist/filesystem.d.ts +3 -0
- package/node_modules/@poe-code/task-list/dist/filesystem.js +32 -0
- package/node_modules/@poe-code/task-list/dist/move.js +3 -3
- package/node_modules/@poe-code/task-list/dist/open.js +2 -5
- package/node_modules/@poe-code/task-list/dist/paths.d.ts +12 -0
- package/node_modules/@poe-code/task-list/dist/paths.js +7 -0
- package/node_modules/@poe-code/task-list/dist/types.d.ts +6 -5
- package/node_modules/@poe-code/task-list/package.json +9 -0
- package/node_modules/@poe-code/terminal-text/LICENSE +21 -0
- package/node_modules/@poe-code/terminal-text/README.md +12 -0
- package/node_modules/@poe-code/terminal-text/dist/index.d.ts +2 -0
- package/node_modules/@poe-code/terminal-text/dist/index.js +20 -0
- package/node_modules/@poe-code/terminal-text/package.json +22 -0
- package/node_modules/@poe-code/xml-ast/LICENSE +21 -0
- package/node_modules/@poe-code/xml-ast/README.md +28 -0
- package/node_modules/@poe-code/xml-ast/dist/index.d.ts +47 -0
- package/node_modules/@poe-code/xml-ast/dist/index.js +635 -0
- package/node_modules/@poe-code/xml-ast/package.json +25 -0
- package/node_modules/auth-store/README.md +35 -0
- package/node_modules/auth-store/dist/index.browser.d.ts +4 -0
- package/node_modules/auth-store/dist/index.browser.js +2 -0
- package/node_modules/auth-store/dist/provider-store.d.ts +1 -1
- package/node_modules/auth-store/dist/safe-fs-secret-store.d.ts +21 -0
- package/node_modules/auth-store/dist/safe-fs-secret-store.js +119 -0
- package/node_modules/auth-store/dist/secret-store.d.ts +12 -0
- package/node_modules/auth-store/dist/secret-store.js +1 -0
- package/node_modules/auth-store/dist/transaction-lock.d.ts +2 -4
- package/node_modules/auth-store/dist/types.d.ts +2 -9
- package/node_modules/auth-store/package.json +16 -2
- package/node_modules/tiny-http-mcp-server/dist/composition.json +16 -1
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/README.md +25 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/authorization-state.js +4 -4
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.js +6 -40
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/oauth-form.d.ts +10 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/oauth-form.js +20 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/pkce.js +4 -3
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/register-client.d.ts +14 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/register-client.js +53 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/resumable.d.ts +16 -2
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/resumable.js +29 -9
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/revoke-token.d.ts +12 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/revoke-token.js +23 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.js +6 -19
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/http-fetch.js +1 -1
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.browser.d.ts +6 -2
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.browser.js +5 -1
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.d.ts +5 -2
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.js +4 -1
- package/node_modules/tiny-http-mcp-server/package.json +4 -4
- package/node_modules/tiny-mcp-client/README.md +2 -0
- package/node_modules/tiny-mcp-client/dist/index.browser.d.ts +25 -23
- package/node_modules/tiny-mcp-client/dist/index.browser.js +116 -1
- package/node_modules/tiny-mcp-client/dist/index.d.ts +25 -23
- package/node_modules/tiny-mcp-client/dist/index.js +1034 -561
- package/node_modules/tiny-mcp-client/package.json +15 -0
- package/node_modules/tiny-stdio-mcp-server/dist/composition.json +1 -1
- package/node_modules/toolcraft-design/dist/components/table.js +6 -0
- package/node_modules/toolcraft-design/dist/escape-terminal-text.d.ts +1 -2
- package/node_modules/toolcraft-design/dist/escape-terminal-text.js +1 -20
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/frontmatter.js +2 -1
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser.js +2 -1
- package/node_modules/toolcraft-schema/dist/json-schema/utils.js +3 -0
- package/node_modules/toolcraft-schema/package.json +1 -1
- package/package.json +32 -7
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
|
|
3
|
+
SHA1 (RFC 3174), MD5 (RFC 1321), and RIPEMD160 legacy, weak hash functions.
|
|
4
|
+
RFC 2286 only covers HMAC-RIPEMD160 wrapper material and test vectors,
|
|
5
|
+
not the base RIPEMD-160 compression spec.
|
|
6
|
+
Don't use them in a new protocol. What "weak" means:
|
|
7
|
+
|
|
8
|
+
- Collisions can be made with 2^18 effort in MD5, 2^60 in SHA1, 2^80 in RIPEMD160.
|
|
9
|
+
- No practical pre-image attacks (only theoretical, 2^123.4)
|
|
10
|
+
- HMAC seems kinda ok: https://www.rfc-editor.org/rfc/rfc6151
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
import { Chi, HashMD, Maj } from "./_md.js";
|
|
14
|
+
import { clean, createHasher, rotl } from "./utils.js";
|
|
15
|
+
/** Initial SHA-1 state from RFC 3174 §6.1. */
|
|
16
|
+
const SHA1_IV = /* @__PURE__ */ Uint32Array.from([
|
|
17
|
+
0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0,
|
|
18
|
+
]);
|
|
19
|
+
// Reusable 80-word SHA-1 message schedule buffer.
|
|
20
|
+
const SHA1_W = /* @__PURE__ */ new Uint32Array(80);
|
|
21
|
+
/** Internal SHA1 legacy hash class. */
|
|
22
|
+
export class _SHA1 extends HashMD {
|
|
23
|
+
A = SHA1_IV[0] | 0;
|
|
24
|
+
B = SHA1_IV[1] | 0;
|
|
25
|
+
C = SHA1_IV[2] | 0;
|
|
26
|
+
D = SHA1_IV[3] | 0;
|
|
27
|
+
E = SHA1_IV[4] | 0;
|
|
28
|
+
constructor() {
|
|
29
|
+
super(64, 20, 8, false);
|
|
30
|
+
}
|
|
31
|
+
get() {
|
|
32
|
+
const { A, B, C, D, E } = this;
|
|
33
|
+
return [A, B, C, D, E];
|
|
34
|
+
}
|
|
35
|
+
set(A, B, C, D, E) {
|
|
36
|
+
this.A = A | 0;
|
|
37
|
+
this.B = B | 0;
|
|
38
|
+
this.C = C | 0;
|
|
39
|
+
this.D = D | 0;
|
|
40
|
+
this.E = E | 0;
|
|
41
|
+
}
|
|
42
|
+
_cloneInto(to) {
|
|
43
|
+
(to ||= new this.constructor()).set(...this.get());
|
|
44
|
+
return this._cloneIntoMeta(to);
|
|
45
|
+
}
|
|
46
|
+
process(view, offset) {
|
|
47
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
48
|
+
SHA1_W[i] = view.getUint32(offset, false);
|
|
49
|
+
for (let i = 16; i < 80; i++)
|
|
50
|
+
SHA1_W[i] = rotl(SHA1_W[i - 3] ^ SHA1_W[i - 8] ^ SHA1_W[i - 14] ^ SHA1_W[i - 16], 1);
|
|
51
|
+
// Compression function main loop, 80 rounds
|
|
52
|
+
let { A, B, C, D, E } = this;
|
|
53
|
+
for (let i = 0; i < 80; i++) {
|
|
54
|
+
let F, K;
|
|
55
|
+
if (i < 20) {
|
|
56
|
+
F = Chi(B, C, D);
|
|
57
|
+
K = 0x5a827999;
|
|
58
|
+
}
|
|
59
|
+
else if (i < 40) {
|
|
60
|
+
F = B ^ C ^ D;
|
|
61
|
+
K = 0x6ed9eba1;
|
|
62
|
+
}
|
|
63
|
+
else if (i < 60) {
|
|
64
|
+
F = Maj(B, C, D);
|
|
65
|
+
K = 0x8f1bbcdc;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
F = B ^ C ^ D;
|
|
69
|
+
K = 0xca62c1d6;
|
|
70
|
+
}
|
|
71
|
+
const T = (rotl(A, 5) + F + E + K + SHA1_W[i]) | 0;
|
|
72
|
+
E = D;
|
|
73
|
+
D = C;
|
|
74
|
+
C = rotl(B, 30);
|
|
75
|
+
B = A;
|
|
76
|
+
A = T;
|
|
77
|
+
}
|
|
78
|
+
// Add the compressed chunk to the current hash value
|
|
79
|
+
A = (A + this.A) | 0;
|
|
80
|
+
B = (B + this.B) | 0;
|
|
81
|
+
C = (C + this.C) | 0;
|
|
82
|
+
D = (D + this.D) | 0;
|
|
83
|
+
E = (E + this.E) | 0;
|
|
84
|
+
this.set(A, B, C, D, E);
|
|
85
|
+
}
|
|
86
|
+
roundClean() {
|
|
87
|
+
clean(SHA1_W);
|
|
88
|
+
}
|
|
89
|
+
destroy() {
|
|
90
|
+
// HashMD callers route post-destroy usability through `destroyed`; zeroizing alone still leaves
|
|
91
|
+
// update()/digest() callable on reused instances.
|
|
92
|
+
this.destroyed = true;
|
|
93
|
+
this.set(0, 0, 0, 0, 0);
|
|
94
|
+
clean(this.buffer);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* SHA1 (RFC 3174) legacy hash function. It was cryptographically broken.
|
|
99
|
+
* @param msg - message bytes to hash
|
|
100
|
+
* @param opts - Reserved hash options.
|
|
101
|
+
* @returns Digest bytes.
|
|
102
|
+
* @example
|
|
103
|
+
* Hash a message with SHA1.
|
|
104
|
+
* ```ts
|
|
105
|
+
* sha1(new Uint8Array([97, 98, 99]));
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export const sha1 = /* @__PURE__ */ createHasher(() => new _SHA1());
|
|
109
|
+
/** RFC 1321 `T[i]` uses `floor(2^32 * abs(sin(i)))`; this is the shared `2^32` scale factor. */
|
|
110
|
+
const p32 = /* @__PURE__ */ Math.pow(2, 32);
|
|
111
|
+
/** RFC 1321 `T[1..64]` table. */
|
|
112
|
+
const K = /* @__PURE__ */ Array.from({ length: 64 }, (_, i) => Math.floor(p32 * Math.abs(Math.sin(i + 1))));
|
|
113
|
+
/** MD5 initial state from RFC 1321, stored as 4 u32 words. */
|
|
114
|
+
const MD5_IV = /* @__PURE__ */ SHA1_IV.slice(0, 4);
|
|
115
|
+
// Reusable 16-word MD5 message block buffer.
|
|
116
|
+
const MD5_W = /* @__PURE__ */ new Uint32Array(16);
|
|
117
|
+
// RFC 1321 §3.4 per-round rotate amounts, flattened to 64 entries so the round loop
|
|
118
|
+
// avoids allocating a 4-element array literal every round (measured ~5% of md5).
|
|
119
|
+
const MD5_SHIFTS = /* @__PURE__ */ (() => {
|
|
120
|
+
const S = [
|
|
121
|
+
[7, 12, 17, 22],
|
|
122
|
+
[5, 9, 14, 20],
|
|
123
|
+
[4, 11, 16, 23],
|
|
124
|
+
[6, 10, 15, 21],
|
|
125
|
+
];
|
|
126
|
+
return Uint8Array.from({ length: 64 }, (_, i) => S[Math.floor(i / 16)][i % 4]);
|
|
127
|
+
})();
|
|
128
|
+
/** Internal MD5 legacy hash class. */
|
|
129
|
+
export class _MD5 extends HashMD {
|
|
130
|
+
A = MD5_IV[0] | 0;
|
|
131
|
+
B = MD5_IV[1] | 0;
|
|
132
|
+
C = MD5_IV[2] | 0;
|
|
133
|
+
D = MD5_IV[3] | 0;
|
|
134
|
+
constructor() {
|
|
135
|
+
super(64, 16, 8, true);
|
|
136
|
+
}
|
|
137
|
+
get() {
|
|
138
|
+
const { A, B, C, D } = this;
|
|
139
|
+
return [A, B, C, D];
|
|
140
|
+
}
|
|
141
|
+
set(A, B, C, D) {
|
|
142
|
+
this.A = A | 0;
|
|
143
|
+
this.B = B | 0;
|
|
144
|
+
this.C = C | 0;
|
|
145
|
+
this.D = D | 0;
|
|
146
|
+
}
|
|
147
|
+
_cloneInto(to) {
|
|
148
|
+
(to ||= new this.constructor()).set(...this.get());
|
|
149
|
+
return this._cloneIntoMeta(to);
|
|
150
|
+
}
|
|
151
|
+
process(view, offset) {
|
|
152
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
153
|
+
MD5_W[i] = view.getUint32(offset, true);
|
|
154
|
+
// Compression function main loop, 64 rounds
|
|
155
|
+
let { A, B, C, D } = this;
|
|
156
|
+
for (let i = 0; i < 64; i++) {
|
|
157
|
+
let F, g;
|
|
158
|
+
if (i < 16) {
|
|
159
|
+
F = Chi(B, C, D);
|
|
160
|
+
g = i;
|
|
161
|
+
}
|
|
162
|
+
else if (i < 32) {
|
|
163
|
+
// RFC 1321 round 2 uses G(B,C,D) = (B & D) | (C & ~D), which is `Chi(D, B, C)`.
|
|
164
|
+
F = Chi(D, B, C);
|
|
165
|
+
g = (5 * i + 1) % 16;
|
|
166
|
+
}
|
|
167
|
+
else if (i < 48) {
|
|
168
|
+
F = B ^ C ^ D;
|
|
169
|
+
g = (3 * i + 5) % 16;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
F = C ^ (B | ~D);
|
|
173
|
+
g = (7 * i) % 16;
|
|
174
|
+
}
|
|
175
|
+
F = F + A + K[i] + MD5_W[g];
|
|
176
|
+
A = D;
|
|
177
|
+
D = C;
|
|
178
|
+
C = B;
|
|
179
|
+
B = B + rotl(F, MD5_SHIFTS[i]);
|
|
180
|
+
}
|
|
181
|
+
// Add the compressed chunk to the current hash value
|
|
182
|
+
A = (A + this.A) | 0;
|
|
183
|
+
B = (B + this.B) | 0;
|
|
184
|
+
C = (C + this.C) | 0;
|
|
185
|
+
D = (D + this.D) | 0;
|
|
186
|
+
this.set(A, B, C, D);
|
|
187
|
+
}
|
|
188
|
+
roundClean() {
|
|
189
|
+
clean(MD5_W);
|
|
190
|
+
}
|
|
191
|
+
destroy() {
|
|
192
|
+
// HashMD callers route post-destroy usability through `destroyed`; zeroizing alone still leaves
|
|
193
|
+
// update()/digest() callable on reused instances.
|
|
194
|
+
this.destroyed = true;
|
|
195
|
+
this.set(0, 0, 0, 0);
|
|
196
|
+
clean(this.buffer);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* MD5 (RFC 1321) legacy hash function. It was cryptographically broken.
|
|
201
|
+
* MD5 architecture is similar to SHA1, with some differences:
|
|
202
|
+
* - Reduced output length: 16 bytes (128 bit) instead of 20
|
|
203
|
+
* - 64 rounds, instead of 80
|
|
204
|
+
* - Little-endian: could be faster, but will require more code
|
|
205
|
+
* - Non-linear index selection: huge speed-up for unroll
|
|
206
|
+
* - Per round constants: more memory accesses, additional speed-up for unroll
|
|
207
|
+
* @param msg - message bytes to hash
|
|
208
|
+
* @param opts - Reserved hash options.
|
|
209
|
+
* @returns Digest bytes.
|
|
210
|
+
* @example
|
|
211
|
+
* Hash a message with MD5.
|
|
212
|
+
* ```ts
|
|
213
|
+
* md5(new Uint8Array([97, 98, 99]));
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
export const md5 = /* @__PURE__ */ createHasher(() => new _MD5());
|
|
217
|
+
// RIPEMD-160
|
|
218
|
+
// Permutation repeatedly applied to derive the later RIPEMD-160 message-order tables.
|
|
219
|
+
const Rho160 = /* @__PURE__ */ Uint8Array.from([
|
|
220
|
+
7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
|
|
221
|
+
]);
|
|
222
|
+
const Id160 = /* @__PURE__ */ (() => Uint8Array.from(new Array(16).fill(0).map((_, i) => i)))();
|
|
223
|
+
const Pi160 = /* @__PURE__ */ (() => Id160.map((i) => (9 * i + 5) % 16))();
|
|
224
|
+
// Five left/right message-word orderings for the RIPEMD-160 dual-lane rounds.
|
|
225
|
+
const idxLR = /* @__PURE__ */ (() => {
|
|
226
|
+
const L = [Id160];
|
|
227
|
+
const R = [Pi160];
|
|
228
|
+
const res = [L, R];
|
|
229
|
+
for (let i = 0; i < 4; i++)
|
|
230
|
+
for (let j of res)
|
|
231
|
+
j.push(j[i].map((k) => Rho160[k]));
|
|
232
|
+
return res;
|
|
233
|
+
})();
|
|
234
|
+
const idxL = /* @__PURE__ */ (() => idxLR[0])();
|
|
235
|
+
const idxR = /* @__PURE__ */ (() => idxLR[1])();
|
|
236
|
+
// const [idxL, idxR] = idxLR;
|
|
237
|
+
// Base per-group shift table before the left/right message-order permutations are applied.
|
|
238
|
+
const shifts160 = /* @__PURE__ */ [
|
|
239
|
+
[11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8],
|
|
240
|
+
[12, 13, 11, 15, 6, 9, 9, 7, 12, 15, 11, 13, 7, 8, 7, 7],
|
|
241
|
+
[13, 15, 14, 11, 7, 7, 6, 8, 13, 14, 13, 12, 5, 5, 6, 9],
|
|
242
|
+
[14, 11, 12, 14, 8, 6, 5, 5, 15, 12, 15, 14, 9, 9, 8, 6],
|
|
243
|
+
[15, 12, 13, 13, 9, 5, 8, 6, 14, 11, 12, 11, 8, 6, 5, 5],
|
|
244
|
+
].map((i) => Uint8Array.from(i));
|
|
245
|
+
const shiftsL160 = /* @__PURE__ */ idxL.map((idx, i) => idx.map((j) => shifts160[i][j]));
|
|
246
|
+
const shiftsR160 = /* @__PURE__ */ idxR.map((idx, i) => idx.map((j) => shifts160[i][j]));
|
|
247
|
+
// Five left-lane additive constants for RIPEMD-160.
|
|
248
|
+
const Kl160 = /* @__PURE__ */ Uint32Array.from([
|
|
249
|
+
0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e,
|
|
250
|
+
]);
|
|
251
|
+
// Five right-lane additive constants for RIPEMD-160.
|
|
252
|
+
const Kr160 = /* @__PURE__ */ Uint32Array.from([
|
|
253
|
+
0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000,
|
|
254
|
+
]);
|
|
255
|
+
// Called `f()` in the spec; valid `group` values are 0..4, and out-of-range
|
|
256
|
+
// inputs currently fall through to the group-4 branch.
|
|
257
|
+
function ripemd_f(group, x, y, z) {
|
|
258
|
+
if (group === 0)
|
|
259
|
+
return x ^ y ^ z;
|
|
260
|
+
if (group === 1)
|
|
261
|
+
return (x & y) | (~x & z);
|
|
262
|
+
if (group === 2)
|
|
263
|
+
return (x | ~y) ^ z;
|
|
264
|
+
if (group === 3)
|
|
265
|
+
return (x & z) | (y & ~z);
|
|
266
|
+
return x ^ (y | ~z);
|
|
267
|
+
}
|
|
268
|
+
// Reusable 16-word RIPEMD-160 message block buffer.
|
|
269
|
+
const BUF_160 = /* @__PURE__ */ new Uint32Array(16);
|
|
270
|
+
/**
|
|
271
|
+
* Internal RIPEMD-160 legacy hash class.
|
|
272
|
+
* RFC 2286 only adds HMAC-RIPEMD160 material, not the core hash specification.
|
|
273
|
+
*/
|
|
274
|
+
export class _RIPEMD160 extends HashMD {
|
|
275
|
+
h0 = 0x67452301 | 0;
|
|
276
|
+
h1 = 0xefcdab89 | 0;
|
|
277
|
+
h2 = 0x98badcfe | 0;
|
|
278
|
+
h3 = 0x10325476 | 0;
|
|
279
|
+
h4 = 0xc3d2e1f0 | 0;
|
|
280
|
+
constructor() {
|
|
281
|
+
super(64, 20, 8, true);
|
|
282
|
+
}
|
|
283
|
+
get() {
|
|
284
|
+
const { h0, h1, h2, h3, h4 } = this;
|
|
285
|
+
return [h0, h1, h2, h3, h4];
|
|
286
|
+
}
|
|
287
|
+
set(h0, h1, h2, h3, h4) {
|
|
288
|
+
this.h0 = h0 | 0;
|
|
289
|
+
this.h1 = h1 | 0;
|
|
290
|
+
this.h2 = h2 | 0;
|
|
291
|
+
this.h3 = h3 | 0;
|
|
292
|
+
this.h4 = h4 | 0;
|
|
293
|
+
}
|
|
294
|
+
_cloneInto(to) {
|
|
295
|
+
(to ||= new this.constructor()).set(...this.get());
|
|
296
|
+
return this._cloneIntoMeta(to);
|
|
297
|
+
}
|
|
298
|
+
process(view, offset) {
|
|
299
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
300
|
+
BUF_160[i] = view.getUint32(offset, true);
|
|
301
|
+
// prettier-ignore
|
|
302
|
+
let al = this.h0 | 0, ar = al, bl = this.h1 | 0, br = bl, cl = this.h2 | 0, cr = cl, dl = this.h3 | 0, dr = dl, el = this.h4 | 0, er = el;
|
|
303
|
+
// Instead of iterating 0 to 80, we split it into 5 groups
|
|
304
|
+
// And use the groups in constants, functions, etc. Much simpler
|
|
305
|
+
for (let group = 0; group < 5; group++) {
|
|
306
|
+
const rGroup = 4 - group;
|
|
307
|
+
const hbl = Kl160[group], hbr = Kr160[group]; // prettier-ignore
|
|
308
|
+
const rl = idxL[group], rr = idxR[group]; // prettier-ignore
|
|
309
|
+
const sl = shiftsL160[group], sr = shiftsR160[group]; // prettier-ignore
|
|
310
|
+
for (let i = 0; i < 16; i++) {
|
|
311
|
+
const tl = (rotl(al + ripemd_f(group, bl, cl, dl) + BUF_160[rl[i]] + hbl, sl[i]) + el) | 0;
|
|
312
|
+
al = el, el = dl, dl = rotl(cl, 10) | 0, cl = bl, bl = tl; // prettier-ignore
|
|
313
|
+
}
|
|
314
|
+
// 2 loops are 10% faster
|
|
315
|
+
for (let i = 0; i < 16; i++) {
|
|
316
|
+
const tr = (rotl(ar + ripemd_f(rGroup, br, cr, dr) + BUF_160[rr[i]] + hbr, sr[i]) + er) | 0;
|
|
317
|
+
ar = er, er = dr, dr = rotl(cr, 10) | 0, cr = br, br = tr; // prettier-ignore
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
// Add the compressed chunk to the current hash value
|
|
321
|
+
// Final recombination cross-adds the left/right lane accumulators into the next h0..h4 order.
|
|
322
|
+
this.set((this.h1 + cl + dr) | 0, (this.h2 + dl + er) | 0, (this.h3 + el + ar) | 0, (this.h4 + al + br) | 0, (this.h0 + bl + cr) | 0);
|
|
323
|
+
}
|
|
324
|
+
roundClean() {
|
|
325
|
+
clean(BUF_160);
|
|
326
|
+
}
|
|
327
|
+
destroy() {
|
|
328
|
+
this.destroyed = true;
|
|
329
|
+
clean(this.buffer);
|
|
330
|
+
this.set(0, 0, 0, 0, 0);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* RIPEMD-160 - a legacy hash function from 1990s.
|
|
335
|
+
* RFC 2286 only covers HMAC-RIPEMD160 test material; the links below point
|
|
336
|
+
* at the base RIPEMD-160 references.
|
|
337
|
+
* * {@link https://homes.esat.kuleuven.be/~bosselae/ripemd160.html}
|
|
338
|
+
* * {@link https://homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf}
|
|
339
|
+
* @param msg - message bytes to hash
|
|
340
|
+
* @param opts - Reserved hash options.
|
|
341
|
+
* @returns Digest bytes.
|
|
342
|
+
* @example
|
|
343
|
+
* Hash a message with RIPEMD-160.
|
|
344
|
+
* ```ts
|
|
345
|
+
* ripemd160(new Uint8Array([97, 98, 99]));
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
export const ripemd160 = /* @__PURE__ */ createHasher(() => new _RIPEMD160());
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@noble/hashes",
|
|
3
|
+
"version": "2.4.0",
|
|
4
|
+
"description": "Audited & minimal 0-dependency JS implementation of SHA, RIPEMD, BLAKE, HMAC, HKDF, PBKDF & Scrypt",
|
|
5
|
+
"files": [
|
|
6
|
+
"*.js",
|
|
7
|
+
"*.d.ts",
|
|
8
|
+
"src"
|
|
9
|
+
],
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@paulmillr/jsbt": "0.7.1",
|
|
12
|
+
"bismar": "0.1.8",
|
|
13
|
+
"@types/node": "26.2.0",
|
|
14
|
+
"fast-check": "4.2.0",
|
|
15
|
+
"prettier": "3.9.6",
|
|
16
|
+
"typescript": "6.0.3"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"benchmark": "node benchmark/hashes.ts",
|
|
20
|
+
"benchmark:thirdparty": "cd benchmark/thirdparty; npm ci; JSBT_BENCHMARK_DIMENSIONS='algorithm,buffer,library' node hashes.ts",
|
|
21
|
+
"benchmark:thirdparty-scrypt": "cd benchmark/thirdparty; npm ci; JSBT_BENCHMARK_DIMENSIONS='iters,library' FILTER='async' node scrypt.ts",
|
|
22
|
+
"benchmark:size": "bismar -bsm",
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"build:clean": "rm *.{js,d.ts} 2> /dev/null",
|
|
25
|
+
"check": "jsbt-check",
|
|
26
|
+
"format": "prettier --write 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'",
|
|
27
|
+
"test": "node test/index.ts",
|
|
28
|
+
"test:dos": "node test/slow-dos.test.ts",
|
|
29
|
+
"test:slow": "node test/slow-big.test.ts",
|
|
30
|
+
"test:acvp": "node test/slow-acvp.test.ts",
|
|
31
|
+
"test:kdf": "node test/slow-kdf.test.ts",
|
|
32
|
+
"test:ultra": "node test/slow-ultra.test.ts",
|
|
33
|
+
"test:ultra:scrypt": "node test/slow-extreme-scrypt.test.ts"
|
|
34
|
+
},
|
|
35
|
+
"exports": {
|
|
36
|
+
".": "./index.js",
|
|
37
|
+
"./_md.js": "./_md.js",
|
|
38
|
+
"./argon2.js": "./argon2.js",
|
|
39
|
+
"./blake1.js": "./blake1.js",
|
|
40
|
+
"./blake2.js": "./blake2.js",
|
|
41
|
+
"./blake3.js": "./blake3.js",
|
|
42
|
+
"./eskdf.js": "./eskdf.js",
|
|
43
|
+
"./hkdf.js": "./hkdf.js",
|
|
44
|
+
"./hmac.js": "./hmac.js",
|
|
45
|
+
"./legacy.js": "./legacy.js",
|
|
46
|
+
"./pbkdf2.js": "./pbkdf2.js",
|
|
47
|
+
"./scrypt.js": "./scrypt.js",
|
|
48
|
+
"./sha2.js": "./sha2.js",
|
|
49
|
+
"./sha3-addons.js": "./sha3-addons.js",
|
|
50
|
+
"./sha3.js": "./sha3.js",
|
|
51
|
+
"./webcrypto.js": "./webcrypto.js",
|
|
52
|
+
"./utils.js": "./utils.js"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">= 20.19.0"
|
|
56
|
+
},
|
|
57
|
+
"keywords": [
|
|
58
|
+
"sha1",
|
|
59
|
+
"sha2",
|
|
60
|
+
"sha3",
|
|
61
|
+
"blake",
|
|
62
|
+
"blake2",
|
|
63
|
+
"blake3",
|
|
64
|
+
"hmac",
|
|
65
|
+
"hkdf",
|
|
66
|
+
"pbkdf2",
|
|
67
|
+
"scrypt",
|
|
68
|
+
"sha256",
|
|
69
|
+
"sha512",
|
|
70
|
+
"keccak",
|
|
71
|
+
"ripemd160",
|
|
72
|
+
"kdf",
|
|
73
|
+
"hash",
|
|
74
|
+
"cryptography",
|
|
75
|
+
"security",
|
|
76
|
+
"noble"
|
|
77
|
+
],
|
|
78
|
+
"homepage": "https://paulmillr.com/noble/",
|
|
79
|
+
"funding": "https://paulmillr.com/funding/",
|
|
80
|
+
"repository": {
|
|
81
|
+
"type": "git",
|
|
82
|
+
"url": "git+https://github.com/paulmillr/noble-hashes.git"
|
|
83
|
+
},
|
|
84
|
+
"type": "module",
|
|
85
|
+
"main": "index.js",
|
|
86
|
+
"module": "index.js",
|
|
87
|
+
"types": "index.d.ts",
|
|
88
|
+
"sideEffects": false,
|
|
89
|
+
"author": "Paul Miller (https://paulmillr.com)",
|
|
90
|
+
"license": "MIT"
|
|
91
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type CHash, type KDFInput, type TArg, type TRet } from './utils.ts';
|
|
2
|
+
/**
|
|
3
|
+
* PBKDF2 options:
|
|
4
|
+
* * c: iterations, should probably be higher than 100_000
|
|
5
|
+
* * dkLen: desired length of derived key in bytes, must be `>= 1` per RFC 8018 §5.2
|
|
6
|
+
* * asyncTick: max time in ms for which async function can block execution
|
|
7
|
+
*/
|
|
8
|
+
export type Pbkdf2Opt = {
|
|
9
|
+
/** Iteration count. Higher values increase CPU cost. */
|
|
10
|
+
c: number;
|
|
11
|
+
/** Desired derived key length in bytes, must be `>= 1` per RFC 8018 §5.2. */
|
|
12
|
+
dkLen?: number;
|
|
13
|
+
/** Max scheduler block time in milliseconds for the async variant. */
|
|
14
|
+
asyncTick?: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* PBKDF2-HMAC: RFC 8018 key derivation function.
|
|
18
|
+
* @param hash - hash function that would be used e.g. sha256
|
|
19
|
+
* @param password - password from which a derived key is generated;
|
|
20
|
+
* JS string inputs are UTF-8 encoded first
|
|
21
|
+
* @param salt - cryptographic salt; JS string inputs are UTF-8 encoded first
|
|
22
|
+
* @param opts - PBKDF2 work factor and output settings. `dkLen`, if provided,
|
|
23
|
+
* must be `>= 1` per RFC 8018 §5.2. See {@link Pbkdf2Opt}.
|
|
24
|
+
* @returns Derived key bytes.
|
|
25
|
+
* @throws If the PBKDF2 iteration count or derived-key settings are invalid. {@link Error}
|
|
26
|
+
* @example
|
|
27
|
+
* PBKDF2-HMAC: RFC 2898 key derivation function.
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { pbkdf2 } from '@noble/hashes/pbkdf2.js';
|
|
30
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
31
|
+
* const key = pbkdf2(sha256, 'password', 'salt', { dkLen: 32, c: Math.pow(2, 18) });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function pbkdf2(hash: TArg<CHash>, password: TArg<KDFInput>, salt: TArg<KDFInput>, opts: Pbkdf2Opt): TRet<Uint8Array>;
|
|
35
|
+
/**
|
|
36
|
+
* PBKDF2-HMAC: RFC 8018 key derivation function. Async version.
|
|
37
|
+
* @param hash - hash function that would be used e.g. sha256
|
|
38
|
+
* @param password - password from which a derived key is generated;
|
|
39
|
+
* JS string inputs are UTF-8 encoded first
|
|
40
|
+
* @param salt - cryptographic salt; JS string inputs are UTF-8 encoded first
|
|
41
|
+
* @param opts - PBKDF2 work factor and output settings. `dkLen`, if provided,
|
|
42
|
+
* must be `>= 1` per RFC 8018 §5.2. `asyncTick` is only a local
|
|
43
|
+
* scheduler-yield knob for this JS wrapper, not part of RFC 8018.
|
|
44
|
+
* See {@link Pbkdf2Opt}.
|
|
45
|
+
* @returns Promise resolving to derived key bytes.
|
|
46
|
+
* @throws If the PBKDF2 iteration count or derived-key settings are invalid. {@link Error}
|
|
47
|
+
* @example
|
|
48
|
+
* PBKDF2-HMAC: RFC 2898 key derivation function.
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { pbkdf2Async } from '@noble/hashes/pbkdf2.js';
|
|
51
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
52
|
+
* const key = await pbkdf2Async(sha256, 'password', 'salt', { dkLen: 32, c: 500_000 });
|
|
53
|
+
* ```
|
|
54
|
+
* @example
|
|
55
|
+
* Tune the async PBKDF2 scheduler for short UI tasks.
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { pbkdf2Async } from '@noble/hashes/pbkdf2.js';
|
|
58
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
59
|
+
* const key = await pbkdf2Async(sha256, 'password', 'salt', {
|
|
60
|
+
* dkLen: 32,
|
|
61
|
+
* c: 32,
|
|
62
|
+
* asyncTick: 1,
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function pbkdf2Async(hash: TArg<CHash>, password: TArg<KDFInput>, salt: TArg<KDFInput>, opts: Pbkdf2Opt): Promise<TRet<Uint8Array>>;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PBKDF (RFC 2898). Can be used to create a key from password and salt.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import { hmac } from "./hmac.js";
|
|
6
|
+
// prettier-ignore
|
|
7
|
+
import { ahash, anumber, asyncLoop, checkOpts, clean, createView, kdfInputToBytes } from "./utils.js";
|
|
8
|
+
// Common validation and per-call state setup for sync/async functions.
|
|
9
|
+
function pbkdf2Init(hash, _password, _salt, _opts) {
|
|
10
|
+
ahash(hash);
|
|
11
|
+
const opts = checkOpts({ dkLen: 32, asyncTick: 10 }, _opts);
|
|
12
|
+
const { c, dkLen, asyncTick } = opts;
|
|
13
|
+
anumber(c, 'c');
|
|
14
|
+
anumber(dkLen, 'dkLen');
|
|
15
|
+
anumber(asyncTick, 'asyncTick');
|
|
16
|
+
if (c < 1)
|
|
17
|
+
throw new Error('"c" (iterations) must be >= 1');
|
|
18
|
+
// RFC 8018 §5.2 defines `dkLen` as "a positive integer".
|
|
19
|
+
if (dkLen < 1)
|
|
20
|
+
throw new Error('"dkLen" must be >= 1');
|
|
21
|
+
// RFC 8018 §5.2 step 1 requires rejecting oversize `dkLen`
|
|
22
|
+
// before allocating the destination buffer.
|
|
23
|
+
if (dkLen > (2 ** 32 - 1) * hash.outputLen)
|
|
24
|
+
throw new Error('derived key too long');
|
|
25
|
+
const p = kdfInputToBytes(_password, 'password');
|
|
26
|
+
try {
|
|
27
|
+
const s = kdfInputToBytes(_salt, 'salt');
|
|
28
|
+
try {
|
|
29
|
+
// DK = PBKDF2(PRF, Password, Salt, c, dkLen);
|
|
30
|
+
const DK = new Uint8Array(dkLen);
|
|
31
|
+
const { iHash, oHash, outputLen } = hmac.create(hash, p);
|
|
32
|
+
// Drive keyed hashes directly; the wrapper is only needed to initialize their HMAC midstates.
|
|
33
|
+
const u = new Uint8Array(outputLen);
|
|
34
|
+
const eng = pbkdf2Engine(iHash, oHash, s, u);
|
|
35
|
+
return { c, dkLen, asyncTick, DK, outputLen, eng };
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
// Uint8Array inputs belong to the caller; only wipe our UTF-8 conversion.
|
|
39
|
+
if (typeof _salt === 'string')
|
|
40
|
+
clean(s);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
if (typeof _password === 'string')
|
|
45
|
+
clean(p);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Per-call PRF driver writes U1 into both `u` and `Ti`, then later digests into `u`;
|
|
49
|
+
// shared by the sync and async variants.
|
|
50
|
+
function pbkdf2Engine(iHash, oHash, salt, u) {
|
|
51
|
+
const counter = new Uint8Array(4);
|
|
52
|
+
const view = createView(counter);
|
|
53
|
+
// Full clones retain tree/config state; absorb salt before async yields without cloning input.
|
|
54
|
+
const salted = iHash._cloneInto().update(salt);
|
|
55
|
+
// u1() overwrites the worker before reading it. Seed from the outer midstate so a long salt
|
|
56
|
+
// cannot pre-populate a tree stack that the first reset would abandon without wiping.
|
|
57
|
+
const work = oHash._cloneInto();
|
|
58
|
+
const iClone = iHash._cloneInto; // Capture before mixed feedback can materialize state tuples.
|
|
59
|
+
const oClone = oHash._cloneInto;
|
|
60
|
+
return {
|
|
61
|
+
u1: (ti, Ti) => {
|
|
62
|
+
view.setInt32(0, ti, false);
|
|
63
|
+
salted._cloneInto(work).update(counter).digestInto(u);
|
|
64
|
+
oHash._cloneInto(work).update(u).digestInto(u);
|
|
65
|
+
Ti.set(u.subarray(0, Ti.length));
|
|
66
|
+
},
|
|
67
|
+
// Whole `F` inner loop for the sync variant: one optimized function owns the hot loop.
|
|
68
|
+
rounds: (c, Ti) => {
|
|
69
|
+
for (let ui = 1; ui < c; ui++) {
|
|
70
|
+
iClone.call(iHash, work).update(u).digestInto(u);
|
|
71
|
+
oClone.call(oHash, work).update(u).digestInto(u);
|
|
72
|
+
for (let i = 0; i < Ti.length; i++)
|
|
73
|
+
Ti[i] ^= u[i];
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
output: (DK) => {
|
|
77
|
+
// Keyed templates and derived worker states are secret material.
|
|
78
|
+
iHash.destroy();
|
|
79
|
+
oHash.destroy();
|
|
80
|
+
salted.destroy();
|
|
81
|
+
work.destroy();
|
|
82
|
+
// Shared sync/async cleanup point: wipe transient PRF state
|
|
83
|
+
// while preserving the derived key buffer.
|
|
84
|
+
clean(u);
|
|
85
|
+
return DK;
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* PBKDF2-HMAC: RFC 8018 key derivation function.
|
|
91
|
+
* @param hash - hash function that would be used e.g. sha256
|
|
92
|
+
* @param password - password from which a derived key is generated;
|
|
93
|
+
* JS string inputs are UTF-8 encoded first
|
|
94
|
+
* @param salt - cryptographic salt; JS string inputs are UTF-8 encoded first
|
|
95
|
+
* @param opts - PBKDF2 work factor and output settings. `dkLen`, if provided,
|
|
96
|
+
* must be `>= 1` per RFC 8018 §5.2. See {@link Pbkdf2Opt}.
|
|
97
|
+
* @returns Derived key bytes.
|
|
98
|
+
* @throws If the PBKDF2 iteration count or derived-key settings are invalid. {@link Error}
|
|
99
|
+
* @example
|
|
100
|
+
* PBKDF2-HMAC: RFC 2898 key derivation function.
|
|
101
|
+
* ```ts
|
|
102
|
+
* import { pbkdf2 } from '@noble/hashes/pbkdf2.js';
|
|
103
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
104
|
+
* const key = pbkdf2(sha256, 'password', 'salt', { dkLen: 32, c: Math.pow(2, 18) });
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export function pbkdf2(hash, password, salt, opts) {
|
|
108
|
+
const { c, dkLen, DK, outputLen, eng } = pbkdf2Init(hash, password, salt, opts);
|
|
109
|
+
// DK = T1 + T2 + ⋯ + Tdklen/hlen
|
|
110
|
+
for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += outputLen) {
|
|
111
|
+
// Ti = F(Password, Salt, c, i)
|
|
112
|
+
// The last Ti view can be shorter than hLen, which applies
|
|
113
|
+
// RFC 8018 §5.2 step 4's T_l<0..r-1> truncation without extra copies.
|
|
114
|
+
const Ti = DK.subarray(pos, pos + outputLen);
|
|
115
|
+
// F(Password, Salt, c, i) = U1 ^ U2 ^ ⋯ ^ Uc
|
|
116
|
+
// U1 = PRF(Password, Salt + INT_32_BE(i))
|
|
117
|
+
eng.u1(ti, Ti);
|
|
118
|
+
// Uc = PRF(Password, Uc−1); Ti ^= Uc
|
|
119
|
+
eng.rounds(c, Ti);
|
|
120
|
+
}
|
|
121
|
+
return eng.output(DK);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* PBKDF2-HMAC: RFC 8018 key derivation function. Async version.
|
|
125
|
+
* @param hash - hash function that would be used e.g. sha256
|
|
126
|
+
* @param password - password from which a derived key is generated;
|
|
127
|
+
* JS string inputs are UTF-8 encoded first
|
|
128
|
+
* @param salt - cryptographic salt; JS string inputs are UTF-8 encoded first
|
|
129
|
+
* @param opts - PBKDF2 work factor and output settings. `dkLen`, if provided,
|
|
130
|
+
* must be `>= 1` per RFC 8018 §5.2. `asyncTick` is only a local
|
|
131
|
+
* scheduler-yield knob for this JS wrapper, not part of RFC 8018.
|
|
132
|
+
* See {@link Pbkdf2Opt}.
|
|
133
|
+
* @returns Promise resolving to derived key bytes.
|
|
134
|
+
* @throws If the PBKDF2 iteration count or derived-key settings are invalid. {@link Error}
|
|
135
|
+
* @example
|
|
136
|
+
* PBKDF2-HMAC: RFC 2898 key derivation function.
|
|
137
|
+
* ```ts
|
|
138
|
+
* import { pbkdf2Async } from '@noble/hashes/pbkdf2.js';
|
|
139
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
140
|
+
* const key = await pbkdf2Async(sha256, 'password', 'salt', { dkLen: 32, c: 500_000 });
|
|
141
|
+
* ```
|
|
142
|
+
* @example
|
|
143
|
+
* Tune the async PBKDF2 scheduler for short UI tasks.
|
|
144
|
+
* ```ts
|
|
145
|
+
* import { pbkdf2Async } from '@noble/hashes/pbkdf2.js';
|
|
146
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
147
|
+
* const key = await pbkdf2Async(sha256, 'password', 'salt', {
|
|
148
|
+
* dkLen: 32,
|
|
149
|
+
* c: 32,
|
|
150
|
+
* asyncTick: 1,
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export async function pbkdf2Async(hash, password, salt, opts) {
|
|
155
|
+
const { c, dkLen, asyncTick, DK, outputLen, eng } = pbkdf2Init(hash, password, salt, opts);
|
|
156
|
+
// Reuse normal state destruction, then wipe the incomplete output if a host yield aborts.
|
|
157
|
+
const abort = () => {
|
|
158
|
+
eng.output(DK);
|
|
159
|
+
clean(DK);
|
|
160
|
+
};
|
|
161
|
+
// DK = T1 + T2 + ⋯ + Tdklen/hlen
|
|
162
|
+
for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += outputLen) {
|
|
163
|
+
// Ti = F(Password, Salt, c, i)
|
|
164
|
+
// The last Ti view can be shorter than hLen, which applies
|
|
165
|
+
// RFC 8018 §5.2 step 4's T_l<0..r-1> truncation without extra copies.
|
|
166
|
+
const Ti = DK.subarray(pos, pos + outputLen);
|
|
167
|
+
// F(Password, Salt, c, i) = U1 ^ U2 ^ ⋯ ^ Uc
|
|
168
|
+
// U1 = PRF(Password, Salt + INT_32_BE(i))
|
|
169
|
+
eng.u1(ti, Ti);
|
|
170
|
+
await asyncLoop(c - 1, asyncTick, () => {
|
|
171
|
+
// Uc = PRF(Password, Uc−1)
|
|
172
|
+
eng.rounds(2, Ti); // c=2 runs exactly one PRF iteration per callback.
|
|
173
|
+
}, abort);
|
|
174
|
+
}
|
|
175
|
+
return eng.output(DK);
|
|
176
|
+
}
|