@awacloud/fw 0.1.0
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/CHANGELOG.md +79 -0
- package/LICENSE +176 -0
- package/NOTICE +12 -0
- package/README.md +355 -0
- package/dist/build/fw.core.pure.meta.json +29 -0
- package/dist/build/fw.core.pure.min.js +26 -0
- package/dist/build/fw.full.pure.meta.json +224 -0
- package/dist/build/fw.full.pure.min.js +60 -0
- package/dist/build/fw.minimal.pure.meta.json +21 -0
- package/dist/build/fw.minimal.pure.min.js +26 -0
- package/dist/build/fw.pack.compress-heavy.pure.meta.json +29 -0
- package/dist/build/fw.pack.compress-heavy.pure.min.js +8 -0
- package/dist/build/fw.pack.crypto-advanced.pure.meta.json +38 -0
- package/dist/build/fw.pack.crypto-advanced.pure.min.js +6 -0
- package/dist/build/fw.pack.crypto-basic.pure.meta.json +29 -0
- package/dist/build/fw.pack.crypto-basic.pure.min.js +6 -0
- package/dist/build/fw.pack.crypto-identity.pure.meta.json +29 -0
- package/dist/build/fw.pack.crypto-identity.pure.min.js +9 -0
- package/dist/build/fw.pack.realtime.pure.meta.json +21 -0
- package/dist/build/fw.pack.realtime.pure.min.js +6 -0
- package/dist/build/fw.pack.sensors.pure.meta.json +21 -0
- package/dist/build/fw.pack.sensors.pure.min.js +6 -0
- package/dist/build/fw.pack.structures-advanced.pure.meta.json +20 -0
- package/dist/build/fw.pack.structures-advanced.pure.min.js +6 -0
- package/dist/build/fw.pack.text-advanced.pure.meta.json +20 -0
- package/dist/build/fw.pack.text-advanced.pure.min.js +6 -0
- package/dist/build/fw.pwa.pure.meta.json +127 -0
- package/dist/build/fw.pwa.pure.min.js +55 -0
- package/dist/build/fw.site-interactive.pure.meta.json +81 -0
- package/dist/build/fw.site-interactive.pure.min.js +52 -0
- package/dist/build/fw.site.pure.meta.json +51 -0
- package/dist/build/fw.site.pure.min.js +35 -0
- package/dist/build/fw.spa.pure.meta.json +108 -0
- package/dist/build/fw.spa.pure.min.js +55 -0
- package/dist/build/io/compress/brotli_dict.bin +432 -0
- package/dist/build/sanity-base-classic.min.js +6 -0
- package/dist/build/sanity-community-classic.min.js +6 -0
- package/dist/build/sanity.min.js +6 -0
- package/dist/types/core/logger.d.ts +71 -0
- package/dist/types/core/logger.d.ts.map +1 -0
- package/dist/types/core/modules.d.ts +3962 -0
- package/dist/types/core/modules.d.ts.map +1 -0
- package/dist/types/core/readyState.d.ts +14 -0
- package/dist/types/core/readyState.d.ts.map +1 -0
- package/dist/types/core/runtime.d.ts +625 -0
- package/dist/types/core/runtime.d.ts.map +1 -0
- package/dist/types/core/worker-helper.d.ts +153 -0
- package/dist/types/core/worker-helper.d.ts.map +1 -0
- package/dist/types/crypto/cipher/aes.d.ts +55 -0
- package/dist/types/crypto/cipher/aes.d.ts.map +1 -0
- package/dist/types/crypto/cipher/chacha20.d.ts +33 -0
- package/dist/types/crypto/cipher/chacha20.d.ts.map +1 -0
- package/dist/types/crypto/hash/adf.d.ts +65 -0
- package/dist/types/crypto/hash/adf.d.ts.map +1 -0
- package/dist/types/crypto/hash/argon2.d.ts +79 -0
- package/dist/types/crypto/hash/argon2.d.ts.map +1 -0
- package/dist/types/crypto/hash/blake2b.d.ts +40 -0
- package/dist/types/crypto/hash/blake2b.d.ts.map +1 -0
- package/dist/types/crypto/hash/hkdf.d.ts +88 -0
- package/dist/types/crypto/hash/hkdf.d.ts.map +1 -0
- package/dist/types/crypto/hash/hmac.d.ts +85 -0
- package/dist/types/crypto/hash/hmac.d.ts.map +1 -0
- package/dist/types/crypto/hash/pbkdf2.d.ts +80 -0
- package/dist/types/crypto/hash/pbkdf2.d.ts.map +1 -0
- package/dist/types/crypto/hash/poly1305.d.ts +31 -0
- package/dist/types/crypto/hash/poly1305.d.ts.map +1 -0
- package/dist/types/crypto/hash/sha224.d.ts +80 -0
- package/dist/types/crypto/hash/sha224.d.ts.map +1 -0
- package/dist/types/crypto/hash/sha256.d.ts +82 -0
- package/dist/types/crypto/hash/sha256.d.ts.map +1 -0
- package/dist/types/crypto/hash/sha3.d.ts +111 -0
- package/dist/types/crypto/hash/sha3.d.ts.map +1 -0
- package/dist/types/crypto/hash/sha384.d.ts +84 -0
- package/dist/types/crypto/hash/sha384.d.ts.map +1 -0
- package/dist/types/crypto/hash/sha512.d.ts +87 -0
- package/dist/types/crypto/hash/sha512.d.ts.map +1 -0
- package/dist/types/crypto/hash/sha512_224.d.ts +84 -0
- package/dist/types/crypto/hash/sha512_224.d.ts.map +1 -0
- package/dist/types/crypto/hash/sha512_256.d.ts +84 -0
- package/dist/types/crypto/hash/sha512_256.d.ts.map +1 -0
- package/dist/types/crypto/mode/cbc.d.ts +38 -0
- package/dist/types/crypto/mode/cbc.d.ts.map +1 -0
- package/dist/types/crypto/mode/chacha20poly1305.d.ts +71 -0
- package/dist/types/crypto/mode/chacha20poly1305.d.ts.map +1 -0
- package/dist/types/crypto/mode/cmac.d.ts +56 -0
- package/dist/types/crypto/mode/cmac.d.ts.map +1 -0
- package/dist/types/crypto/mode/ctr.d.ts +52 -0
- package/dist/types/crypto/mode/ctr.d.ts.map +1 -0
- package/dist/types/crypto/mode/gcm.d.ts +88 -0
- package/dist/types/crypto/mode/gcm.d.ts.map +1 -0
- package/dist/types/crypto/mode/kw.d.ts +60 -0
- package/dist/types/crypto/mode/kw.d.ts.map +1 -0
- package/dist/types/crypto/pkc/ecc.d.ts +284 -0
- package/dist/types/crypto/pkc/ecc.d.ts.map +1 -0
- package/dist/types/crypto/pkc/ed25519.d.ts +107 -0
- package/dist/types/crypto/pkc/ed25519.d.ts.map +1 -0
- package/dist/types/crypto/pkc/hybridKem.d.ts +154 -0
- package/dist/types/crypto/pkc/hybridKem.d.ts.map +1 -0
- package/dist/types/crypto/pkc/hybridSign.d.ts +383 -0
- package/dist/types/crypto/pkc/hybridSign.d.ts.map +1 -0
- package/dist/types/crypto/pkc/ml_dsa.d.ts +174 -0
- package/dist/types/crypto/pkc/ml_dsa.d.ts.map +1 -0
- package/dist/types/crypto/pkc/ml_kem.d.ts +194 -0
- package/dist/types/crypto/pkc/ml_kem.d.ts.map +1 -0
- package/dist/types/crypto/pkc/rsa.d.ts +175 -0
- package/dist/types/crypto/pkc/rsa.d.ts.map +1 -0
- package/dist/types/crypto/pkc/slh_dsa.d.ts +232 -0
- package/dist/types/crypto/pkc/slh_dsa.d.ts.map +1 -0
- package/dist/types/crypto/pkc/x25519.d.ts +37 -0
- package/dist/types/crypto/pkc/x25519.d.ts.map +1 -0
- package/dist/types/crypto/utils/aes_ctr.d.ts +84 -0
- package/dist/types/crypto/utils/aes_ctr.d.ts.map +1 -0
- package/dist/types/crypto/utils/aes_modes.d.ts +128 -0
- package/dist/types/crypto/utils/aes_modes.d.ts.map +1 -0
- package/dist/types/crypto/utils/asn1-oid.d.ts +45 -0
- package/dist/types/crypto/utils/asn1-oid.d.ts.map +1 -0
- package/dist/types/crypto/utils/asn1.d.ts +115 -0
- package/dist/types/crypto/utils/asn1.d.ts.map +1 -0
- package/dist/types/crypto/utils/bitArray.d.ts +75 -0
- package/dist/types/crypto/utils/bitArray.d.ts.map +1 -0
- package/dist/types/crypto/utils/bn.d.ts +214 -0
- package/dist/types/crypto/utils/bn.d.ts.map +1 -0
- package/dist/types/crypto/utils/jws.d.ts +159 -0
- package/dist/types/crypto/utils/jws.d.ts.map +1 -0
- package/dist/types/crypto/utils/keyformat.d.ts +100 -0
- package/dist/types/crypto/utils/keyformat.d.ts.map +1 -0
- package/dist/types/crypto/utils/pad.d.ts +44 -0
- package/dist/types/crypto/utils/pad.d.ts.map +1 -0
- package/dist/types/crypto/utils/pem.d.ts +41 -0
- package/dist/types/crypto/utils/pem.d.ts.map +1 -0
- package/dist/types/crypto/utils/random.d.ts +203 -0
- package/dist/types/crypto/utils/random.d.ts.map +1 -0
- package/dist/types/crypto/utils/rsaKeygen.d.ts +162 -0
- package/dist/types/crypto/utils/rsaKeygen.d.ts.map +1 -0
- package/dist/types/crypto/utils/totp.d.ts +183 -0
- package/dist/types/crypto/utils/totp.d.ts.map +1 -0
- package/dist/types/crypto/utils/uuid.d.ts +29 -0
- package/dist/types/crypto/utils/uuid.d.ts.map +1 -0
- package/dist/types/crypto/wasm/aes.d.ts +59 -0
- package/dist/types/crypto/wasm/aes.d.ts.map +1 -0
- package/dist/types/crypto/wasm/argon2.d.ts +70 -0
- package/dist/types/crypto/wasm/argon2.d.ts.map +1 -0
- package/dist/types/crypto/wasm/blake2b.d.ts +59 -0
- package/dist/types/crypto/wasm/blake2b.d.ts.map +1 -0
- package/dist/types/crypto/wasm/chacha20poly1305.d.ts +43 -0
- package/dist/types/crypto/wasm/chacha20poly1305.d.ts.map +1 -0
- package/dist/types/crypto/wasm/cmac.d.ts +42 -0
- package/dist/types/crypto/wasm/cmac.d.ts.map +1 -0
- package/dist/types/crypto/wasm/ecc.d.ts +56 -0
- package/dist/types/crypto/wasm/ecc.d.ts.map +1 -0
- package/dist/types/crypto/wasm/ed25519.d.ts +52 -0
- package/dist/types/crypto/wasm/ed25519.d.ts.map +1 -0
- package/dist/types/crypto/wasm/hkdf.d.ts +40 -0
- package/dist/types/crypto/wasm/hkdf.d.ts.map +1 -0
- package/dist/types/crypto/wasm/hmac.d.ts +42 -0
- package/dist/types/crypto/wasm/hmac.d.ts.map +1 -0
- package/dist/types/crypto/wasm/ml_dsa.d.ts +48 -0
- package/dist/types/crypto/wasm/ml_dsa.d.ts.map +1 -0
- package/dist/types/crypto/wasm/ml_kem.d.ts +58 -0
- package/dist/types/crypto/wasm/ml_kem.d.ts.map +1 -0
- package/dist/types/crypto/wasm/pbkdf2.d.ts +38 -0
- package/dist/types/crypto/wasm/pbkdf2.d.ts.map +1 -0
- package/dist/types/crypto/wasm/rsa.d.ts +56 -0
- package/dist/types/crypto/wasm/rsa.d.ts.map +1 -0
- package/dist/types/crypto/wasm/runtime.d.ts +99 -0
- package/dist/types/crypto/wasm/runtime.d.ts.map +1 -0
- package/dist/types/crypto/wasm/sha2.d.ts +45 -0
- package/dist/types/crypto/wasm/sha2.d.ts.map +1 -0
- package/dist/types/crypto/wasm/sha3.d.ts +57 -0
- package/dist/types/crypto/wasm/sha3.d.ts.map +1 -0
- package/dist/types/crypto/wasm/slh_dsa.d.ts +62 -0
- package/dist/types/crypto/wasm/slh_dsa.d.ts.map +1 -0
- package/dist/types/crypto/wasm/x25519.d.ts +53 -0
- package/dist/types/crypto/wasm/x25519.d.ts.map +1 -0
- package/dist/types/crypto/webcrypto/aes.d.ts +59 -0
- package/dist/types/crypto/webcrypto/aes.d.ts.map +1 -0
- package/dist/types/crypto/webcrypto/aeskw.d.ts +40 -0
- package/dist/types/crypto/webcrypto/aeskw.d.ts.map +1 -0
- package/dist/types/crypto/webcrypto/digest.d.ts +43 -0
- package/dist/types/crypto/webcrypto/digest.d.ts.map +1 -0
- package/dist/types/crypto/webcrypto/ecc.d.ts +51 -0
- package/dist/types/crypto/webcrypto/ecc.d.ts.map +1 -0
- package/dist/types/crypto/webcrypto/ed25519.d.ts +43 -0
- package/dist/types/crypto/webcrypto/ed25519.d.ts.map +1 -0
- package/dist/types/crypto/webcrypto/hkdf.d.ts +18 -0
- package/dist/types/crypto/webcrypto/hkdf.d.ts.map +1 -0
- package/dist/types/crypto/webcrypto/hmac.d.ts +43 -0
- package/dist/types/crypto/webcrypto/hmac.d.ts.map +1 -0
- package/dist/types/crypto/webcrypto/pbkdf2.d.ts +18 -0
- package/dist/types/crypto/webcrypto/pbkdf2.d.ts.map +1 -0
- package/dist/types/crypto/webcrypto/rsa.d.ts +51 -0
- package/dist/types/crypto/webcrypto/rsa.d.ts.map +1 -0
- package/dist/types/crypto/webcrypto/x25519.d.ts +43 -0
- package/dist/types/crypto/webcrypto/x25519.d.ts.map +1 -0
- package/dist/types/dom/display/animate.d.ts +35 -0
- package/dist/types/dom/display/animate.d.ts.map +1 -0
- package/dist/types/dom/display/fullscreen.d.ts +59 -0
- package/dist/types/dom/display/fullscreen.d.ts.map +1 -0
- package/dist/types/dom/fs/download.d.ts +36 -0
- package/dist/types/dom/fs/download.d.ts.map +1 -0
- package/dist/types/dom/fs/fsAccess.d.ts +107 -0
- package/dist/types/dom/fs/fsAccess.d.ts.map +1 -0
- package/dist/types/dom/fs/indexedDB.d.ts +62 -0
- package/dist/types/dom/fs/indexedDB.d.ts.map +1 -0
- package/dist/types/dom/fs/remoteStore.d.ts +64 -0
- package/dist/types/dom/fs/remoteStore.d.ts.map +1 -0
- package/dist/types/dom/fs/storage.d.ts +56 -0
- package/dist/types/dom/fs/storage.d.ts.map +1 -0
- package/dist/types/dom/lifecycle/idle.d.ts +91 -0
- package/dist/types/dom/lifecycle/idle.d.ts.map +1 -0
- package/dist/types/dom/lifecycle/visibility.d.ts +49 -0
- package/dist/types/dom/lifecycle/visibility.d.ts.map +1 -0
- package/dist/types/dom/lifecycle/wakeLock.d.ts +69 -0
- package/dist/types/dom/lifecycle/wakeLock.d.ts.map +1 -0
- package/dist/types/dom/net/ajax.d.ts +27 -0
- package/dist/types/dom/net/ajax.d.ts.map +1 -0
- package/dist/types/dom/net/broadcastChannel.d.ts +51 -0
- package/dist/types/dom/net/broadcastChannel.d.ts.map +1 -0
- package/dist/types/dom/net/network.d.ts +80 -0
- package/dist/types/dom/net/network.d.ts.map +1 -0
- package/dist/types/dom/net/sse.d.ts +72 -0
- package/dist/types/dom/net/sse.d.ts.map +1 -0
- package/dist/types/dom/net/webrtc.d.ts +149 -0
- package/dist/types/dom/net/webrtc.d.ts.map +1 -0
- package/dist/types/dom/net/ws.d.ts +70 -0
- package/dist/types/dom/net/ws.d.ts.map +1 -0
- package/dist/types/dom/query/dnd.d.ts +86 -0
- package/dist/types/dom/query/dnd.d.ts.map +1 -0
- package/dist/types/dom/query/dom.d.ts +194 -0
- package/dist/types/dom/query/dom.d.ts.map +1 -0
- package/dist/types/dom/query/events.d.ts +135 -0
- package/dist/types/dom/query/events.d.ts.map +1 -0
- package/dist/types/dom/query/gesture.d.ts +59 -0
- package/dist/types/dom/query/gesture.d.ts.map +1 -0
- package/dist/types/dom/query/media.d.ts +156 -0
- package/dist/types/dom/query/media.d.ts.map +1 -0
- package/dist/types/dom/rendering/chart.d.ts +143 -0
- package/dist/types/dom/rendering/chart.d.ts.map +1 -0
- package/dist/types/dom/rendering/component.d.ts +92 -0
- package/dist/types/dom/rendering/component.d.ts.map +1 -0
- package/dist/types/dom/rendering/devtools-ui.d.ts +83 -0
- package/dist/types/dom/rendering/devtools-ui.d.ts.map +1 -0
- package/dist/types/dom/rendering/devtools.d.ts +68 -0
- package/dist/types/dom/rendering/devtools.d.ts.map +1 -0
- package/dist/types/dom/rendering/parser.d.ts +216 -0
- package/dist/types/dom/rendering/parser.d.ts.map +1 -0
- package/dist/types/dom/rendering/reactiveBind.d.ts +101 -0
- package/dist/types/dom/rendering/reactiveBind.d.ts.map +1 -0
- package/dist/types/dom/rendering/render.d.ts +121 -0
- package/dist/types/dom/rendering/render.d.ts.map +1 -0
- package/dist/types/dom/rendering/sanitize.d.ts +48 -0
- package/dist/types/dom/rendering/sanitize.d.ts.map +1 -0
- package/dist/types/dom/rendering/secPolicy.d.ts +89 -0
- package/dist/types/dom/rendering/secPolicy.d.ts.map +1 -0
- package/dist/types/dom/rendering/template.d.ts +251 -0
- package/dist/types/dom/rendering/template.d.ts.map +1 -0
- package/dist/types/dom/rendering/themeTokens.d.ts +61 -0
- package/dist/types/dom/rendering/themeTokens.d.ts.map +1 -0
- package/dist/types/dom/rendering/uiSession-core.d.ts +192 -0
- package/dist/types/dom/rendering/uiSession-core.d.ts.map +1 -0
- package/dist/types/dom/rendering/uiSession-direct.d.ts +63 -0
- package/dist/types/dom/rendering/uiSession-direct.d.ts.map +1 -0
- package/dist/types/dom/rendering/uiSession-list.d.ts +205 -0
- package/dist/types/dom/rendering/uiSession-list.d.ts.map +1 -0
- package/dist/types/dom/rendering/uiSession.d.ts +285 -0
- package/dist/types/dom/rendering/uiSession.d.ts.map +1 -0
- package/dist/types/dom/rendering/virtualScroll.d.ts +80 -0
- package/dist/types/dom/rendering/virtualScroll.d.ts.map +1 -0
- package/dist/types/dom/sensors/battery.d.ts +71 -0
- package/dist/types/dom/sensors/battery.d.ts.map +1 -0
- package/dist/types/dom/sensors/geolocation.d.ts +83 -0
- package/dist/types/dom/sensors/geolocation.d.ts.map +1 -0
- package/dist/types/dom/sensors/networkInfo.d.ts +82 -0
- package/dist/types/dom/sensors/networkInfo.d.ts.map +1 -0
- package/dist/types/dom/sensors/sensors.d.ts +191 -0
- package/dist/types/dom/sensors/sensors.d.ts.map +1 -0
- package/dist/types/dom/sw/backgroundSync.d.ts +48 -0
- package/dist/types/dom/sw/backgroundSync.d.ts.map +1 -0
- package/dist/types/dom/sw/cache.d.ts +71 -0
- package/dist/types/dom/sw/cache.d.ts.map +1 -0
- package/dist/types/dom/sw/push.d.ts +77 -0
- package/dist/types/dom/sw/push.d.ts.map +1 -0
- package/dist/types/dom/sw/serviceWorker.d.ts +57 -0
- package/dist/types/dom/sw/serviceWorker.d.ts.map +1 -0
- package/dist/types/dom/sw/sharedWorker.d.ts +81 -0
- package/dist/types/dom/sw/sharedWorker.d.ts.map +1 -0
- package/dist/types/dom/utils/a11y.d.ts +53 -0
- package/dist/types/dom/utils/a11y.d.ts.map +1 -0
- package/dist/types/dom/utils/clipboard.d.ts +44 -0
- package/dist/types/dom/utils/clipboard.d.ts.map +1 -0
- package/dist/types/dom/utils/entropyCollector.d.ts +58 -0
- package/dist/types/dom/utils/entropyCollector.d.ts.map +1 -0
- package/dist/types/dom/utils/focus.d.ts +123 -0
- package/dist/types/dom/utils/focus.d.ts.map +1 -0
- package/dist/types/dom/utils/form.d.ts +227 -0
- package/dist/types/dom/utils/form.d.ts.map +1 -0
- package/dist/types/dom/utils/formKit.d.ts +206 -0
- package/dist/types/dom/utils/formKit.d.ts.map +1 -0
- package/dist/types/dom/utils/keybindings.d.ts +53 -0
- package/dist/types/dom/utils/keybindings.d.ts.map +1 -0
- package/dist/types/dom/utils/leaderElection.d.ts +70 -0
- package/dist/types/dom/utils/leaderElection.d.ts.map +1 -0
- package/dist/types/dom/utils/notifications.d.ts +164 -0
- package/dist/types/dom/utils/notifications.d.ts.map +1 -0
- package/dist/types/dom/utils/permissions.d.ts +35 -0
- package/dist/types/dom/utils/permissions.d.ts.map +1 -0
- package/dist/types/dom/utils/route.d.ts +117 -0
- package/dist/types/dom/utils/route.d.ts.map +1 -0
- package/dist/types/dom/utils/ua.d.ts +35 -0
- package/dist/types/dom/utils/ua.d.ts.map +1 -0
- package/dist/types/dom/utils/webauthn.d.ts +98 -0
- package/dist/types/dom/utils/webauthn.d.ts.map +1 -0
- package/dist/types/io/binary/reader.d.ts +59 -0
- package/dist/types/io/binary/reader.d.ts.map +1 -0
- package/dist/types/io/binary/writer.d.ts +56 -0
- package/dist/types/io/binary/writer.d.ts.map +1 -0
- package/dist/types/io/calc/adler32.d.ts +31 -0
- package/dist/types/io/calc/adler32.d.ts.map +1 -0
- package/dist/types/io/calc/bigint.d.ts +74 -0
- package/dist/types/io/calc/bigint.d.ts.map +1 -0
- package/dist/types/io/calc/crc32.d.ts +36 -0
- package/dist/types/io/calc/crc32.d.ts.map +1 -0
- package/dist/types/io/calc/easing.d.ts +60 -0
- package/dist/types/io/calc/easing.d.ts.map +1 -0
- package/dist/types/io/codec/b64.d.ts +28 -0
- package/dist/types/io/codec/b64.d.ts.map +1 -0
- package/dist/types/io/codec/base32.d.ts +28 -0
- package/dist/types/io/codec/base32.d.ts.map +1 -0
- package/dist/types/io/codec/base58.d.ts +28 -0
- package/dist/types/io/codec/base58.d.ts.map +1 -0
- package/dist/types/io/codec/buffer.d.ts +66 -0
- package/dist/types/io/codec/buffer.d.ts.map +1 -0
- package/dist/types/io/codec/cbor.d.ts +43 -0
- package/dist/types/io/codec/cbor.d.ts.map +1 -0
- package/dist/types/io/codec/csv.d.ts +35 -0
- package/dist/types/io/codec/csv.d.ts.map +1 -0
- package/dist/types/io/codec/hex.d.ts +28 -0
- package/dist/types/io/codec/hex.d.ts.map +1 -0
- package/dist/types/io/codec/mime.d.ts +100 -0
- package/dist/types/io/codec/mime.d.ts.map +1 -0
- package/dist/types/io/codec/msgpack.d.ts +36 -0
- package/dist/types/io/codec/msgpack.d.ts.map +1 -0
- package/dist/types/io/codec/url.d.ts +52 -0
- package/dist/types/io/codec/url.d.ts.map +1 -0
- package/dist/types/io/codec/utf8.d.ts +22 -0
- package/dist/types/io/codec/utf8.d.ts.map +1 -0
- package/dist/types/io/codec/xml.d.ts +91 -0
- package/dist/types/io/codec/xml.d.ts.map +1 -0
- package/dist/types/io/compress/bitstream.d.ts +51 -0
- package/dist/types/io/compress/bitstream.d.ts.map +1 -0
- package/dist/types/io/compress/brotli.d.ts +86 -0
- package/dist/types/io/compress/brotli.d.ts.map +1 -0
- package/dist/types/io/compress/brotli_dict.d.ts +76 -0
- package/dist/types/io/compress/brotli_dict.d.ts.map +1 -0
- package/dist/types/io/compress/brotli_dict_words.d.ts +43 -0
- package/dist/types/io/compress/brotli_dict_words.d.ts.map +1 -0
- package/dist/types/io/compress/brotli_frame.d.ts +166 -0
- package/dist/types/io/compress/brotli_frame.d.ts.map +1 -0
- package/dist/types/io/compress/brotli_shared.d.ts +165 -0
- package/dist/types/io/compress/brotli_shared.d.ts.map +1 -0
- package/dist/types/io/compress/deflate.d.ts +89 -0
- package/dist/types/io/compress/deflate.d.ts.map +1 -0
- package/dist/types/io/compress/gzip.d.ts +100 -0
- package/dist/types/io/compress/gzip.d.ts.map +1 -0
- package/dist/types/io/compress/huffman.d.ts +37 -0
- package/dist/types/io/compress/huffman.d.ts.map +1 -0
- package/dist/types/io/compress/lz4.d.ts +45 -0
- package/dist/types/io/compress/lz4.d.ts.map +1 -0
- package/dist/types/io/compress/lz77.d.ts +66 -0
- package/dist/types/io/compress/lz77.d.ts.map +1 -0
- package/dist/types/io/compress/lzw.d.ts +37 -0
- package/dist/types/io/compress/lzw.d.ts.map +1 -0
- package/dist/types/io/compress/zip.d.ts +112 -0
- package/dist/types/io/compress/zip.d.ts.map +1 -0
- package/dist/types/io/compress/zlib.d.ts +97 -0
- package/dist/types/io/compress/zlib.d.ts.map +1 -0
- package/dist/types/io/i18n/i18n.d.ts +64 -0
- package/dist/types/io/i18n/i18n.d.ts.map +1 -0
- package/dist/types/io/math/fixed-point.d.ts +30 -0
- package/dist/types/io/math/fixed-point.d.ts.map +1 -0
- package/dist/types/io/math/geom.d.ts +125 -0
- package/dist/types/io/math/geom.d.ts.map +1 -0
- package/dist/types/io/math/interp.d.ts +48 -0
- package/dist/types/io/math/interp.d.ts.map +1 -0
- package/dist/types/io/math/linalg.d.ts +117 -0
- package/dist/types/io/math/linalg.d.ts.map +1 -0
- package/dist/types/io/math/stats.d.ts +45 -0
- package/dist/types/io/math/stats.d.ts.map +1 -0
- package/dist/types/io/structures/btree.d.ts +84 -0
- package/dist/types/io/structures/btree.d.ts.map +1 -0
- package/dist/types/io/structures/heap.d.ts +75 -0
- package/dist/types/io/structures/heap.d.ts.map +1 -0
- package/dist/types/io/structures/lruCache.d.ts +88 -0
- package/dist/types/io/structures/lruCache.d.ts.map +1 -0
- package/dist/types/io/structures/ringBuffer.d.ts +82 -0
- package/dist/types/io/structures/ringBuffer.d.ts.map +1 -0
- package/dist/types/io/structures/tree-walker.d.ts +95 -0
- package/dist/types/io/structures/tree-walker.d.ts.map +1 -0
- package/dist/types/io/structures/trie.d.ts +71 -0
- package/dist/types/io/structures/trie.d.ts.map +1 -0
- package/dist/types/io/sync/abort.d.ts +59 -0
- package/dist/types/io/sync/abort.d.ts.map +1 -0
- package/dist/types/io/sync/atomics.d.ts +107 -0
- package/dist/types/io/sync/atomics.d.ts.map +1 -0
- package/dist/types/io/sync/cancellable.d.ts +69 -0
- package/dist/types/io/sync/cancellable.d.ts.map +1 -0
- package/dist/types/io/sync/channel.d.ts +70 -0
- package/dist/types/io/sync/channel.d.ts.map +1 -0
- package/dist/types/io/sync/mutex.d.ts +39 -0
- package/dist/types/io/sync/mutex.d.ts.map +1 -0
- package/dist/types/io/sync/semaphore.d.ts +40 -0
- package/dist/types/io/sync/semaphore.d.ts.map +1 -0
- package/dist/types/io/sync/tokenBucket.d.ts +53 -0
- package/dist/types/io/sync/tokenBucket.d.ts.map +1 -0
- package/dist/types/io/text/ansi.d.ts +125 -0
- package/dist/types/io/text/ansi.d.ts.map +1 -0
- package/dist/types/io/text/html-entities.d.ts +35 -0
- package/dist/types/io/text/html-entities.d.ts.map +1 -0
- package/dist/types/io/text/semver.d.ts +75 -0
- package/dist/types/io/text/semver.d.ts.map +1 -0
- package/dist/types/io/text/str.d.ts +88 -0
- package/dist/types/io/text/str.d.ts.map +1 -0
- package/dist/types/io/text/unicode.d.ts +70 -0
- package/dist/types/io/text/unicode.d.ts.map +1 -0
- package/dist/types/io/time/date.d.ts +73 -0
- package/dist/types/io/time/date.d.ts.map +1 -0
- package/dist/types/io/timing/clock.d.ts +39 -0
- package/dist/types/io/timing/clock.d.ts.map +1 -0
- package/dist/types/io/timing/rateLimit.d.ts +40 -0
- package/dist/types/io/timing/rateLimit.d.ts.map +1 -0
- package/dist/types/io/timing/scheduler.d.ts +122 -0
- package/dist/types/io/timing/scheduler.d.ts.map +1 -0
- package/dist/types/io/utils/bitmap.d.ts +34 -0
- package/dist/types/io/utils/bitmap.d.ts.map +1 -0
- package/dist/types/io/utils/errors.d.ts +94 -0
- package/dist/types/io/utils/errors.d.ts.map +1 -0
- package/dist/types/io/utils/eventBus.d.ts +68 -0
- package/dist/types/io/utils/eventBus.d.ts.map +1 -0
- package/dist/types/io/utils/queue.d.ts +69 -0
- package/dist/types/io/utils/queue.d.ts.map +1 -0
- package/dist/types/io/utils/signal.d.ts +362 -0
- package/dist/types/io/utils/signal.d.ts.map +1 -0
- package/dist/types/io/utils/ui8.d.ts +34 -0
- package/dist/types/io/utils/ui8.d.ts.map +1 -0
- package/dist/types/io/utils/valid.d.ts +130 -0
- package/dist/types/io/utils/valid.d.ts.map +1 -0
- package/dist/types/main.d.ts +25 -0
- package/dist/types/main.d.ts.map +1 -0
- package/dist/types/process/message.d.ts +64 -0
- package/dist/types/process/message.d.ts.map +1 -0
- package/dist/types/process/rpc.d.ts +35 -0
- package/dist/types/process/rpc.d.ts.map +1 -0
- package/dist/types/process/workerPool.d.ts +62 -0
- package/dist/types/process/workerPool.d.ts.map +1 -0
- package/dist/types/sanity/base.d.ts +28 -0
- package/dist/types/sanity/base.d.ts.map +1 -0
- package/dist/types/sanity/community.d.ts +20 -0
- package/dist/types/sanity/community.d.ts.map +1 -0
- package/dist/types/sanity/lockdown-apply.d.ts +7 -0
- package/dist/types/sanity/lockdown-apply.d.ts.map +1 -0
- package/dist/types/sanity/lockdown.d.ts +43 -0
- package/dist/types/sanity/lockdown.d.ts.map +1 -0
- package/dist/types/sanity/wasm-gate.d.ts +128 -0
- package/dist/types/sanity/wasm-gate.d.ts.map +1 -0
- package/docs/README.md +301 -0
- package/docs/api/README.md +33 -0
- package/docs/api/core/README.md +14 -0
- package/docs/api/core/logger.md +151 -0
- package/docs/api/core/main.md +105 -0
- package/docs/api/core/modules.md +123 -0
- package/docs/api/core/readyState.md +94 -0
- package/docs/api/core/runtime.md +499 -0
- package/docs/api/core/worker-helper.md +180 -0
- package/docs/api/crypto/README.md +39 -0
- package/docs/api/crypto/cipher/README.md +24 -0
- package/docs/api/crypto/cipher/aes.md +101 -0
- package/docs/api/crypto/cipher/chacha20.md +85 -0
- package/docs/api/crypto/hash/README.md +49 -0
- package/docs/api/crypto/hash/adf.md +61 -0
- package/docs/api/crypto/hash/argon2.md +92 -0
- package/docs/api/crypto/hash/blake2b.md +88 -0
- package/docs/api/crypto/hash/hkdf.md +82 -0
- package/docs/api/crypto/hash/hmac.md +90 -0
- package/docs/api/crypto/hash/pbkdf2.md +93 -0
- package/docs/api/crypto/hash/poly1305.md +71 -0
- package/docs/api/crypto/hash/sha224.md +61 -0
- package/docs/api/crypto/hash/sha256.md +84 -0
- package/docs/api/crypto/hash/sha3.md +89 -0
- package/docs/api/crypto/hash/sha384.md +58 -0
- package/docs/api/crypto/hash/sha512.md +73 -0
- package/docs/api/crypto/hash/sha512_224.md +59 -0
- package/docs/api/crypto/hash/sha512_256.md +58 -0
- package/docs/api/crypto/mode/README.md +33 -0
- package/docs/api/crypto/mode/cbc.md +69 -0
- package/docs/api/crypto/mode/chacha20poly1305.md +77 -0
- package/docs/api/crypto/mode/cmac.md +79 -0
- package/docs/api/crypto/mode/ctr.md +66 -0
- package/docs/api/crypto/mode/gcm.md +93 -0
- package/docs/api/crypto/mode/kw.md +84 -0
- package/docs/api/crypto/pkc/README.md +48 -0
- package/docs/api/crypto/pkc/ecc.md +91 -0
- package/docs/api/crypto/pkc/ed25519.md +99 -0
- package/docs/api/crypto/pkc/hybridKem.md +178 -0
- package/docs/api/crypto/pkc/hybridSign.md +192 -0
- package/docs/api/crypto/pkc/ml_dsa.md +99 -0
- package/docs/api/crypto/pkc/ml_kem.md +90 -0
- package/docs/api/crypto/pkc/rsa.md +87 -0
- package/docs/api/crypto/pkc/slh_dsa.md +86 -0
- package/docs/api/crypto/pkc/x25519.md +84 -0
- package/docs/api/crypto/utils/README.md +39 -0
- package/docs/api/crypto/utils/aes_ctr.md +71 -0
- package/docs/api/crypto/utils/aes_modes.md +81 -0
- package/docs/api/crypto/utils/asn1-oid.md +130 -0
- package/docs/api/crypto/utils/asn1.md +69 -0
- package/docs/api/crypto/utils/bitArray.md +77 -0
- package/docs/api/crypto/utils/bn.md +67 -0
- package/docs/api/crypto/utils/jws.md +94 -0
- package/docs/api/crypto/utils/keyformat.md +78 -0
- package/docs/api/crypto/utils/pad.md +66 -0
- package/docs/api/crypto/utils/pem.md +63 -0
- package/docs/api/crypto/utils/random.md +103 -0
- package/docs/api/crypto/utils/rsaKeygen.md +118 -0
- package/docs/api/crypto/utils/totp.md +159 -0
- package/docs/api/crypto/utils/uuid.md +98 -0
- package/docs/api/crypto/wasm/README.md +76 -0
- package/docs/api/crypto/wasm/aes.md +128 -0
- package/docs/api/crypto/wasm/argon2.md +110 -0
- package/docs/api/crypto/wasm/blake2b.md +103 -0
- package/docs/api/crypto/wasm/chacha20poly1305.md +120 -0
- package/docs/api/crypto/wasm/cmac.md +119 -0
- package/docs/api/crypto/wasm/ecc.md +114 -0
- package/docs/api/crypto/wasm/ed25519.md +117 -0
- package/docs/api/crypto/wasm/hkdf.md +163 -0
- package/docs/api/crypto/wasm/hmac.md +129 -0
- package/docs/api/crypto/wasm/ml_dsa.md +99 -0
- package/docs/api/crypto/wasm/ml_kem.md +91 -0
- package/docs/api/crypto/wasm/pbkdf2.md +111 -0
- package/docs/api/crypto/wasm/rsa.md +113 -0
- package/docs/api/crypto/wasm/runtime.md +172 -0
- package/docs/api/crypto/wasm/sha2.md +95 -0
- package/docs/api/crypto/wasm/sha3.md +127 -0
- package/docs/api/crypto/wasm/slh_dsa.md +89 -0
- package/docs/api/crypto/wasm/x25519.md +116 -0
- package/docs/api/crypto/webcrypto/README.md +56 -0
- package/docs/api/crypto/webcrypto/aes.md +140 -0
- package/docs/api/crypto/webcrypto/aeskw.md +120 -0
- package/docs/api/crypto/webcrypto/digest.md +103 -0
- package/docs/api/crypto/webcrypto/ecc.md +122 -0
- package/docs/api/crypto/webcrypto/ed25519.md +121 -0
- package/docs/api/crypto/webcrypto/hkdf.md +141 -0
- package/docs/api/crypto/webcrypto/hmac.md +112 -0
- package/docs/api/crypto/webcrypto/pbkdf2.md +140 -0
- package/docs/api/crypto/webcrypto/rsa.md +149 -0
- package/docs/api/crypto/webcrypto/x25519.md +96 -0
- package/docs/api/dom/README.md +117 -0
- package/docs/api/dom/display/README.md +27 -0
- package/docs/api/dom/display/animate.md +113 -0
- package/docs/api/dom/display/fullscreen.md +121 -0
- package/docs/api/dom/fs/README.md +36 -0
- package/docs/api/dom/fs/download.md +108 -0
- package/docs/api/dom/fs/fsAccess.md +200 -0
- package/docs/api/dom/fs/indexedDB.md +219 -0
- package/docs/api/dom/fs/remoteStore.md +158 -0
- package/docs/api/dom/fs/storage.md +197 -0
- package/docs/api/dom/lifecycle/README.md +11 -0
- package/docs/api/dom/lifecycle/idle.md +89 -0
- package/docs/api/dom/lifecycle/visibility.md +73 -0
- package/docs/api/dom/lifecycle/wakeLock.md +94 -0
- package/docs/api/dom/net/README.md +31 -0
- package/docs/api/dom/net/ajax.md +176 -0
- package/docs/api/dom/net/broadcastChannel.md +110 -0
- package/docs/api/dom/net/network.md +137 -0
- package/docs/api/dom/net/sse.md +141 -0
- package/docs/api/dom/net/webrtc.md +158 -0
- package/docs/api/dom/net/ws.md +168 -0
- package/docs/api/dom/query/README.md +30 -0
- package/docs/api/dom/query/dnd.md +137 -0
- package/docs/api/dom/query/dom.md +275 -0
- package/docs/api/dom/query/events.md +211 -0
- package/docs/api/dom/query/gesture.md +137 -0
- package/docs/api/dom/query/media.md +188 -0
- package/docs/api/dom/rendering/README.md +41 -0
- package/docs/api/dom/rendering/chart.md +149 -0
- package/docs/api/dom/rendering/component.md +287 -0
- package/docs/api/dom/rendering/devtools-ui.md +129 -0
- package/docs/api/dom/rendering/devtools.md +157 -0
- package/docs/api/dom/rendering/parser.md +200 -0
- package/docs/api/dom/rendering/reactiveBind.md +234 -0
- package/docs/api/dom/rendering/render.md +219 -0
- package/docs/api/dom/rendering/sanitize.md +97 -0
- package/docs/api/dom/rendering/secPolicy.md +155 -0
- package/docs/api/dom/rendering/template.md +301 -0
- package/docs/api/dom/rendering/themeTokens.md +175 -0
- package/docs/api/dom/rendering/uiSession.md +546 -0
- package/docs/api/dom/rendering/virtualScroll.md +126 -0
- package/docs/api/dom/sensors/README.md +12 -0
- package/docs/api/dom/sensors/battery.md +70 -0
- package/docs/api/dom/sensors/geolocation.md +115 -0
- package/docs/api/dom/sensors/networkInfo.md +73 -0
- package/docs/api/dom/sensors/sensors.md +123 -0
- package/docs/api/dom/sw/README.md +31 -0
- package/docs/api/dom/sw/backgroundSync.md +145 -0
- package/docs/api/dom/sw/cache.md +116 -0
- package/docs/api/dom/sw/push.md +114 -0
- package/docs/api/dom/sw/serviceWorker.md +90 -0
- package/docs/api/dom/sw/sharedWorker.md +131 -0
- package/docs/api/dom/utils/README.md +25 -0
- package/docs/api/dom/utils/a11y.md +143 -0
- package/docs/api/dom/utils/clipboard.md +146 -0
- package/docs/api/dom/utils/entropyCollector.md +175 -0
- package/docs/api/dom/utils/focus.md +140 -0
- package/docs/api/dom/utils/form.md +196 -0
- package/docs/api/dom/utils/formKit.md +181 -0
- package/docs/api/dom/utils/keybindings.md +138 -0
- package/docs/api/dom/utils/leaderElection.md +130 -0
- package/docs/api/dom/utils/notifications.md +106 -0
- package/docs/api/dom/utils/permissions.md +82 -0
- package/docs/api/dom/utils/route.md +112 -0
- package/docs/api/dom/utils/ua.md +119 -0
- package/docs/api/dom/utils/webauthn.md +190 -0
- package/docs/api/io/README.md +20 -0
- package/docs/api/io/binary/README.md +29 -0
- package/docs/api/io/binary/reader.md +126 -0
- package/docs/api/io/binary/writer.md +127 -0
- package/docs/api/io/calc/README.md +22 -0
- package/docs/api/io/calc/adler32.md +75 -0
- package/docs/api/io/calc/bigint.md +105 -0
- package/docs/api/io/calc/crc32.md +74 -0
- package/docs/api/io/calc/easing.md +118 -0
- package/docs/api/io/codec/README.md +35 -0
- package/docs/api/io/codec/b64.md +92 -0
- package/docs/api/io/codec/base32.md +98 -0
- package/docs/api/io/codec/base58.md +104 -0
- package/docs/api/io/codec/buffer.md +144 -0
- package/docs/api/io/codec/cbor.md +179 -0
- package/docs/api/io/codec/csv.md +178 -0
- package/docs/api/io/codec/hex.md +75 -0
- package/docs/api/io/codec/mime.md +156 -0
- package/docs/api/io/codec/msgpack.md +142 -0
- package/docs/api/io/codec/url.md +265 -0
- package/docs/api/io/codec/utf8.md +84 -0
- package/docs/api/io/codec/xml.md +87 -0
- package/docs/api/io/compress/README.md +62 -0
- package/docs/api/io/compress/bitstream.md +131 -0
- package/docs/api/io/compress/brotli.md +232 -0
- package/docs/api/io/compress/brotli_dict.md +119 -0
- package/docs/api/io/compress/brotli_dict_words.md +142 -0
- package/docs/api/io/compress/brotli_frame.md +214 -0
- package/docs/api/io/compress/brotli_shared.md +144 -0
- package/docs/api/io/compress/deflate.md +474 -0
- package/docs/api/io/compress/gzip.md +130 -0
- package/docs/api/io/compress/huffman.md +210 -0
- package/docs/api/io/compress/lz4.md +278 -0
- package/docs/api/io/compress/lz77.md +180 -0
- package/docs/api/io/compress/lzw.md +121 -0
- package/docs/api/io/compress/zip.md +209 -0
- package/docs/api/io/compress/zlib.md +125 -0
- package/docs/api/io/i18n/README.md +23 -0
- package/docs/api/io/i18n/i18n.md +128 -0
- package/docs/api/io/math/README.md +24 -0
- package/docs/api/io/math/fixed-point.md +115 -0
- package/docs/api/io/math/geom.md +144 -0
- package/docs/api/io/math/interp.md +115 -0
- package/docs/api/io/math/linalg.md +138 -0
- package/docs/api/io/math/stats.md +109 -0
- package/docs/api/io/structures/README.md +31 -0
- package/docs/api/io/structures/btree.md +155 -0
- package/docs/api/io/structures/heap.md +166 -0
- package/docs/api/io/structures/lruCache.md +156 -0
- package/docs/api/io/structures/ringBuffer.md +188 -0
- package/docs/api/io/structures/tree-walker.md +132 -0
- package/docs/api/io/structures/trie.md +138 -0
- package/docs/api/io/sync/README.md +29 -0
- package/docs/api/io/sync/abort.md +129 -0
- package/docs/api/io/sync/atomics.md +159 -0
- package/docs/api/io/sync/cancellable.md +176 -0
- package/docs/api/io/sync/channel.md +125 -0
- package/docs/api/io/sync/mutex.md +93 -0
- package/docs/api/io/sync/semaphore.md +106 -0
- package/docs/api/io/sync/tokenBucket.md +139 -0
- package/docs/api/io/text/README.md +23 -0
- package/docs/api/io/text/ansi.md +182 -0
- package/docs/api/io/text/html-entities.md +79 -0
- package/docs/api/io/text/semver.md +158 -0
- package/docs/api/io/text/str.md +129 -0
- package/docs/api/io/text/unicode.md +89 -0
- package/docs/api/io/time/README.md +22 -0
- package/docs/api/io/time/date.md +128 -0
- package/docs/api/io/timing/README.md +32 -0
- package/docs/api/io/timing/clock.md +102 -0
- package/docs/api/io/timing/rateLimit.md +137 -0
- package/docs/api/io/timing/scheduler.md +163 -0
- package/docs/api/io/utils/README.md +30 -0
- package/docs/api/io/utils/bitmap.md +96 -0
- package/docs/api/io/utils/errors.md +165 -0
- package/docs/api/io/utils/eventBus.md +162 -0
- package/docs/api/io/utils/queue.md +141 -0
- package/docs/api/io/utils/signal.md +388 -0
- package/docs/api/io/utils/ui8.md +111 -0
- package/docs/api/io/utils/valid.md +272 -0
- package/docs/api/process/README.md +18 -0
- package/docs/api/process/message.md +166 -0
- package/docs/api/process/rpc.md +161 -0
- package/docs/api/process/workerPool.md +130 -0
- package/docs/api/sanity/base.md +132 -0
- package/docs/api/sanity/community.md +96 -0
- package/docs/api/sanity/lockdown.md +128 -0
- package/docs/api/typed.md +85 -0
- package/docs/dev/README.md +25 -0
- package/docs/dev/provenance.md +80 -0
- package/docs/dev/publishing.md +31 -0
- package/docs/dev/runtime.md +64 -0
- package/docs/dev/testing.md +61 -0
- package/docs/dev/types.md +35 -0
- package/docs/evidence/pqc-hybrid-evidence.md +438 -0
- package/docs/guide/README.md +38 -0
- package/docs/guide/_QUICK_REF.md +341 -0
- package/docs/guide/by-use-case.md +160 -0
- package/docs/guide/doc-format.md +306 -0
- package/docs/guide/gesture-dnd-side-channel.md +119 -0
- package/docs/guide/getting-started.md +134 -0
- package/docs/guide/hmr.md +187 -0
- package/docs/guide/integration-bundlers.md +193 -0
- package/docs/guide/integrations-hmr.md +103 -0
- package/docs/guide/module-creation-workflow.md +342 -0
- package/docs/guide/module-pattern.md +244 -0
- package/docs/guide/rendering-pipeline.md +422 -0
- package/docs/guide/security.md +346 -0
- package/docs/guide/test-format.md +190 -0
- package/docs/guide/tutorial-todo.md +298 -0
- package/docs/guide/typescript.md +215 -0
- package/docs/guide/worker-confinement.md +301 -0
- package/docs/guide/workers.md +168 -0
- package/docs/notes/lz77-deflate-factorization.md +96 -0
- package/docs/notes/worker-confinement-spike.md +302 -0
- package/docs/tools/README.md +56 -0
- package/docs/tools/aot.md +108 -0
- package/docs/tools/audit.md +61 -0
- package/docs/tools/bundler.md +215 -0
- package/docs/tools/codegen.md +64 -0
- package/docs/tools/jsx.md +236 -0
- package/docs/tools/precompilation.md +88 -0
- package/docs/tools/standalone.md +107 -0
- package/fw.config.json +129 -0
- package/integrations/README.md +52 -0
- package/integrations/_shared/catalog.generated.json +207 -0
- package/integrations/_shared/config-resolve.js +201 -0
- package/integrations/_shared/core.js +362 -0
- package/integrations/astro/README.md +96 -0
- package/integrations/astro/index.d.ts +42 -0
- package/integrations/astro/index.js +94 -0
- package/integrations/bun/README.md +62 -0
- package/integrations/bun/index.d.ts +30 -0
- package/integrations/bun/index.js +134 -0
- package/integrations/deno/README.md +55 -0
- package/integrations/deno/deno.json +10 -0
- package/integrations/esbuild/README.md +75 -0
- package/integrations/esbuild/backend.js +147 -0
- package/integrations/esbuild/index.d.ts +32 -0
- package/integrations/esbuild/index.js +147 -0
- package/integrations/eslint/README.md +27 -0
- package/integrations/eslint/no-factory-capture.js +99 -0
- package/integrations/jest/README.md +45 -0
- package/integrations/jest/bun-test-shim.js +43 -0
- package/integrations/nestjs/README.md +68 -0
- package/integrations/nestjs/index.d.ts +38 -0
- package/integrations/nestjs/index.js +99 -0
- package/integrations/nextjs/README.md +149 -0
- package/integrations/nextjs/index.d.ts +30 -0
- package/integrations/nextjs/index.js +98 -0
- package/integrations/nodejs/README.md +46 -0
- package/integrations/nodejs/package.node.example.json +31 -0
- package/integrations/rollup/README.md +65 -0
- package/integrations/rollup/backend.js +132 -0
- package/integrations/rollup/index.d.ts +32 -0
- package/integrations/rollup/index.js +84 -0
- package/integrations/turbopack/README.md +56 -0
- package/integrations/turbopack/index.d.ts +47 -0
- package/integrations/turbopack/index.js +164 -0
- package/integrations/typedoc/README.md +57 -0
- package/integrations/typedoc/categorize.js +121 -0
- package/integrations/typedoc/tsconfig.typedoc.json +14 -0
- package/integrations/typedoc/typedoc.json +19 -0
- package/integrations/vite/README.md +115 -0
- package/integrations/vite/index.d.ts +29 -0
- package/integrations/vite/index.js +182 -0
- package/integrations/vite/package.json +8 -0
- package/integrations/vite/vite-env.d.ts +36 -0
- package/integrations/vitest/README.md +77 -0
- package/integrations/vitest/bun-test-shim.js +92 -0
- package/integrations/vitest/vitest.config.js +41 -0
- package/integrations/webpack/README.md +53 -0
- package/integrations/webpack/index.d.ts +29 -0
- package/integrations/webpack/index.js +182 -0
- package/package.json +303 -0
- package/src/core/logger.js +373 -0
- package/src/core/modules.js +289 -0
- package/src/core/readyState.js +119 -0
- package/src/core/runtime.js +929 -0
- package/src/core/worker-helper.js +261 -0
- package/src/crypto/NIST_CONFORMANCE.md +249 -0
- package/src/crypto/cipher/aes.acvp.md +74 -0
- package/src/crypto/cipher/aes.js +512 -0
- package/src/crypto/cipher/chacha20.acvp.md +117 -0
- package/src/crypto/cipher/chacha20.js +147 -0
- package/src/crypto/hash/adf.acvp.md +144 -0
- package/src/crypto/hash/adf.js +127 -0
- package/src/crypto/hash/argon2.acvp.md +144 -0
- package/src/crypto/hash/argon2.js +517 -0
- package/src/crypto/hash/blake2b.acvp.md +122 -0
- package/src/crypto/hash/blake2b.js +367 -0
- package/src/crypto/hash/hkdf.acvp.md +128 -0
- package/src/crypto/hash/hkdf.js +145 -0
- package/src/crypto/hash/hmac.acvp.md +110 -0
- package/src/crypto/hash/hmac.js +177 -0
- package/src/crypto/hash/pbkdf2.acvp.md +122 -0
- package/src/crypto/hash/pbkdf2.js +120 -0
- package/src/crypto/hash/poly1305.acvp.md +111 -0
- package/src/crypto/hash/poly1305.js +126 -0
- package/src/crypto/hash/sha224.acvp.md +81 -0
- package/src/crypto/hash/sha224.js +60 -0
- package/src/crypto/hash/sha256.acvp.md +75 -0
- package/src/crypto/hash/sha256.js +217 -0
- package/src/crypto/hash/sha3.acvp.md +133 -0
- package/src/crypto/hash/sha3.js +391 -0
- package/src/crypto/hash/sha384.acvp.md +82 -0
- package/src/crypto/hash/sha384.js +61 -0
- package/src/crypto/hash/sha512.acvp.md +84 -0
- package/src/crypto/hash/sha512.js +314 -0
- package/src/crypto/hash/sha512_224.acvp.md +90 -0
- package/src/crypto/hash/sha512_224.js +66 -0
- package/src/crypto/hash/sha512_256.acvp.md +96 -0
- package/src/crypto/hash/sha512_256.js +75 -0
- package/src/crypto/mode/cbc.acvp.md +105 -0
- package/src/crypto/mode/cbc.js +136 -0
- package/src/crypto/mode/chacha20poly1305.acvp.md +116 -0
- package/src/crypto/mode/chacha20poly1305.js +190 -0
- package/src/crypto/mode/cmac.acvp.md +106 -0
- package/src/crypto/mode/cmac.js +172 -0
- package/src/crypto/mode/ctr.acvp.md +110 -0
- package/src/crypto/mode/ctr.js +174 -0
- package/src/crypto/mode/gcm.acvp.md +129 -0
- package/src/crypto/mode/gcm.js +333 -0
- package/src/crypto/mode/kw.acvp.md +145 -0
- package/src/crypto/mode/kw.js +323 -0
- package/src/crypto/pkc/ecc.acvp.md +181 -0
- package/src/crypto/pkc/ecc.js +941 -0
- package/src/crypto/pkc/ed25519.acvp.md +172 -0
- package/src/crypto/pkc/ed25519.js +582 -0
- package/src/crypto/pkc/hybrid-kat.provenance.md +89 -0
- package/src/crypto/pkc/hybridKem.js +255 -0
- package/src/crypto/pkc/hybridSign.js +437 -0
- package/src/crypto/pkc/ml_dsa.acvp.md +146 -0
- package/src/crypto/pkc/ml_dsa.js +984 -0
- package/src/crypto/pkc/ml_kem.acvp.md +117 -0
- package/src/crypto/pkc/ml_kem.js +596 -0
- package/src/crypto/pkc/rsa.acvp.md +187 -0
- package/src/crypto/pkc/rsa.js +470 -0
- package/src/crypto/pkc/slh_dsa.acvp.md +155 -0
- package/src/crypto/pkc/slh_dsa.js +820 -0
- package/src/crypto/pkc/x25519.acvp.md +113 -0
- package/src/crypto/pkc/x25519.js +290 -0
- package/src/crypto/utils/aes_ctr.acvp.md +67 -0
- package/src/crypto/utils/aes_ctr.js +134 -0
- package/src/crypto/utils/aes_modes.acvp.md +66 -0
- package/src/crypto/utils/aes_modes.js +241 -0
- package/src/crypto/utils/asn1-oid.js +369 -0
- package/src/crypto/utils/asn1.js +343 -0
- package/src/crypto/utils/bitArray.js +312 -0
- package/src/crypto/utils/bn.js +825 -0
- package/src/crypto/utils/jws.js +222 -0
- package/src/crypto/utils/keyformat.js +303 -0
- package/src/crypto/utils/pad.js +198 -0
- package/src/crypto/utils/pem.js +90 -0
- package/src/crypto/utils/random.acvp.md +167 -0
- package/src/crypto/utils/random.js +846 -0
- package/src/crypto/utils/rsaKeygen.acvp.md +158 -0
- package/src/crypto/utils/rsaKeygen.js +448 -0
- package/src/crypto/utils/totp.js +409 -0
- package/src/crypto/utils/uuid.acvp.md +137 -0
- package/src/crypto/utils/uuid.js +176 -0
- package/src/crypto/wasm/aes.js +494 -0
- package/src/crypto/wasm/argon2.js +236 -0
- package/src/crypto/wasm/blake2b.js +213 -0
- package/src/crypto/wasm/chacha20poly1305.js +238 -0
- package/src/crypto/wasm/cmac.js +207 -0
- package/src/crypto/wasm/ecc.js +437 -0
- package/src/crypto/wasm/ed25519.js +307 -0
- package/src/crypto/wasm/hkdf.js +183 -0
- package/src/crypto/wasm/hmac.js +215 -0
- package/src/crypto/wasm/ml_dsa.js +375 -0
- package/src/crypto/wasm/ml_kem.js +313 -0
- package/src/crypto/wasm/pbkdf2.js +205 -0
- package/src/crypto/wasm/rsa.js +674 -0
- package/src/crypto/wasm/runtime.js +400 -0
- package/src/crypto/wasm/sha2.js +183 -0
- package/src/crypto/wasm/sha3.js +221 -0
- package/src/crypto/wasm/slh_dsa.js +397 -0
- package/src/crypto/wasm/x25519.js +241 -0
- package/src/crypto/webcrypto/aes.js +370 -0
- package/src/crypto/webcrypto/aeskw.js +185 -0
- package/src/crypto/webcrypto/digest.js +136 -0
- package/src/crypto/webcrypto/ecc.js +371 -0
- package/src/crypto/webcrypto/ed25519.js +248 -0
- package/src/crypto/webcrypto/hkdf.js +132 -0
- package/src/crypto/webcrypto/hmac.js +213 -0
- package/src/crypto/webcrypto/pbkdf2.js +146 -0
- package/src/crypto/webcrypto/rsa.js +415 -0
- package/src/crypto/webcrypto/x25519.js +250 -0
- package/src/dom/display/animate.js +154 -0
- package/src/dom/display/fullscreen.js +305 -0
- package/src/dom/fs/download.js +118 -0
- package/src/dom/fs/fsAccess.js +307 -0
- package/src/dom/fs/indexedDB.js +465 -0
- package/src/dom/fs/remoteStore.js +484 -0
- package/src/dom/fs/storage.js +440 -0
- package/src/dom/lifecycle/idle.js +133 -0
- package/src/dom/lifecycle/visibility.js +140 -0
- package/src/dom/lifecycle/wakeLock.js +187 -0
- package/src/dom/net/ajax.js +303 -0
- package/src/dom/net/broadcastChannel.js +89 -0
- package/src/dom/net/network.js +260 -0
- package/src/dom/net/sse.js +295 -0
- package/src/dom/net/webrtc.js +381 -0
- package/src/dom/net/ws.js +290 -0
- package/src/dom/query/dnd.js +409 -0
- package/src/dom/query/dom.js +831 -0
- package/src/dom/query/events.js +425 -0
- package/src/dom/query/gesture.js +396 -0
- package/src/dom/query/media.js +616 -0
- package/src/dom/rendering/chart.js +663 -0
- package/src/dom/rendering/component.js +469 -0
- package/src/dom/rendering/devtools-ui.js +399 -0
- package/src/dom/rendering/devtools.js +352 -0
- package/src/dom/rendering/parser.js +1055 -0
- package/src/dom/rendering/reactiveBind.js +341 -0
- package/src/dom/rendering/render.js +601 -0
- package/src/dom/rendering/sanitize.js +364 -0
- package/src/dom/rendering/secPolicy.js +281 -0
- package/src/dom/rendering/template.js +1031 -0
- package/src/dom/rendering/themeTokens.js +522 -0
- package/src/dom/rendering/uiSession-core.js +597 -0
- package/src/dom/rendering/uiSession-direct.js +251 -0
- package/src/dom/rendering/uiSession-list.js +751 -0
- package/src/dom/rendering/uiSession.js +145 -0
- package/src/dom/rendering/virtualScroll.js +341 -0
- package/src/dom/sensors/battery.js +153 -0
- package/src/dom/sensors/geolocation.js +156 -0
- package/src/dom/sensors/networkInfo.js +136 -0
- package/src/dom/sensors/sensors.js +340 -0
- package/src/dom/sw/backgroundSync.js +113 -0
- package/src/dom/sw/cache.js +139 -0
- package/src/dom/sw/push.js +181 -0
- package/src/dom/sw/serviceWorker.js +193 -0
- package/src/dom/sw/sharedWorker.js +192 -0
- package/src/dom/utils/a11y.js +244 -0
- package/src/dom/utils/clipboard.js +113 -0
- package/src/dom/utils/entropyCollector.js +344 -0
- package/src/dom/utils/focus.js +421 -0
- package/src/dom/utils/form.js +535 -0
- package/src/dom/utils/formKit.js +427 -0
- package/src/dom/utils/keybindings.js +574 -0
- package/src/dom/utils/leaderElection.js +280 -0
- package/src/dom/utils/notifications.js +218 -0
- package/src/dom/utils/permissions.js +107 -0
- package/src/dom/utils/route.js +482 -0
- package/src/dom/utils/ua.js +109 -0
- package/src/dom/utils/webauthn.js +369 -0
- package/src/external/README.md +15 -0
- package/src/io/binary/reader.js +374 -0
- package/src/io/binary/writer.js +351 -0
- package/src/io/calc/adler32.js +94 -0
- package/src/io/calc/bigint.js +276 -0
- package/src/io/calc/crc32.js +111 -0
- package/src/io/calc/easing.js +514 -0
- package/src/io/codec/b64.js +235 -0
- package/src/io/codec/base32.js +147 -0
- package/src/io/codec/base58.js +167 -0
- package/src/io/codec/buffer.js +630 -0
- package/src/io/codec/cbor.js +550 -0
- package/src/io/codec/csv.js +299 -0
- package/src/io/codec/hex.js +129 -0
- package/src/io/codec/mime.js +398 -0
- package/src/io/codec/msgpack.js +491 -0
- package/src/io/codec/url.js +530 -0
- package/src/io/codec/utf8.js +181 -0
- package/src/io/codec/xml.js +428 -0
- package/src/io/compress/bitstream.js +199 -0
- package/src/io/compress/brotli.js +3073 -0
- package/src/io/compress/brotli_dict.bin +432 -0
- package/src/io/compress/brotli_dict.js +356 -0
- package/src/io/compress/brotli_dict_words.js +157 -0
- package/src/io/compress/brotli_frame.js +420 -0
- package/src/io/compress/brotli_shared.js +715 -0
- package/src/io/compress/deflate.js +1432 -0
- package/src/io/compress/gzip.js +406 -0
- package/src/io/compress/huffman.js +322 -0
- package/src/io/compress/lz4.js +451 -0
- package/src/io/compress/lz77.js +408 -0
- package/src/io/compress/lzw.js +332 -0
- package/src/io/compress/zip.js +815 -0
- package/src/io/compress/zlib.js +340 -0
- package/src/io/i18n/i18n.js +236 -0
- package/src/io/math/fixed-point.js +269 -0
- package/src/io/math/geom.js +350 -0
- package/src/io/math/interp.js +263 -0
- package/src/io/math/linalg.js +472 -0
- package/src/io/math/stats.js +339 -0
- package/src/io/structures/btree.js +357 -0
- package/src/io/structures/heap.js +249 -0
- package/src/io/structures/lruCache.js +219 -0
- package/src/io/structures/ringBuffer.js +208 -0
- package/src/io/structures/tree-walker.js +413 -0
- package/src/io/structures/trie.js +219 -0
- package/src/io/sync/abort.js +196 -0
- package/src/io/sync/atomics.js +342 -0
- package/src/io/sync/cancellable.js +279 -0
- package/src/io/sync/channel.js +301 -0
- package/src/io/sync/mutex.js +148 -0
- package/src/io/sync/semaphore.js +156 -0
- package/src/io/sync/tokenBucket.js +208 -0
- package/src/io/text/ansi.js +536 -0
- package/src/io/text/html-entities.js +143 -0
- package/src/io/text/semver.js +375 -0
- package/src/io/text/str.js +243 -0
- package/src/io/text/unicode.js +188 -0
- package/src/io/time/date.js +355 -0
- package/src/io/timing/clock.js +79 -0
- package/src/io/timing/rateLimit.js +264 -0
- package/src/io/timing/scheduler.js +351 -0
- package/src/io/utils/bitmap.js +94 -0
- package/src/io/utils/errors.js +269 -0
- package/src/io/utils/eventBus.js +315 -0
- package/src/io/utils/queue.js +223 -0
- package/src/io/utils/signal.js +858 -0
- package/src/io/utils/ui8.js +99 -0
- package/src/io/utils/valid.js +556 -0
- package/src/main.js +41 -0
- package/src/polyfill/README.md +9 -0
- package/src/process/message.js +257 -0
- package/src/process/rpc.js +286 -0
- package/src/process/workerPool.js +392 -0
- package/src/sanity/base.js +374 -0
- package/src/sanity/community.js +254 -0
- package/src/sanity/lockdown-apply.js +58 -0
- package/src/sanity/lockdown.js +408 -0
- package/src/sanity/wasm-gate.js +316 -0
- package/src/typed.js +53 -0
- package/third-party/NOTICE-penner-easing +88 -0
- package/third-party/NOTICE-sjcl +50 -0
- package/tools/_lib/cli-help.js +55 -0
- package/tools/rendering/aot/index.js +148 -0
- package/tools/rendering/aot/lib/dom-codegen.js +295 -0
- package/tools/rendering/jsx/index.js +654 -0
- package/tools/rendering/precompilation/index.js +368 -0
- package/types/registry.generated.d.ts +217 -0
- package/types/typed.d.ts +106 -0
|
@@ -0,0 +1,984 @@
|
|
|
1
|
+
// Copyright (c) 2026 AwaCloud SAS
|
|
2
|
+
// Author: Matthieu Bouilloux
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview ML-DSA (Module-Lattice-based Digital Signature Algorithm).
|
|
7
|
+
*
|
|
8
|
+
* Implements FIPS 204 (a.k.a. CRYSTALS-Dilithium). Three parameter sets:
|
|
9
|
+
* ML-DSA-44, ML-DSA-65, ML-DSA-87.
|
|
10
|
+
*
|
|
11
|
+
* Public API per parameter set:
|
|
12
|
+
* keygen(seed32?) → { publicKey, secretKey }
|
|
13
|
+
* sign(msg, sk, ctx?, rnd?) → signature (or false on internal failure)
|
|
14
|
+
* verify(sig, msg, pk, ctx?) → boolean
|
|
15
|
+
*
|
|
16
|
+
* Determinism:
|
|
17
|
+
* - keygen(seed) is deterministic.
|
|
18
|
+
* - sign(msg, sk, ctx, rnd=zeros) is deterministic ("ML-DSA hedged with
|
|
19
|
+
* zero entropy", aka the FIPS 204 deterministic mode).
|
|
20
|
+
* - With no rnd, 32 random bytes are drawn from the CSPRNG.
|
|
21
|
+
*
|
|
22
|
+
* Hash bindings (FIPS 204 §3.7):
|
|
23
|
+
* H_eta uses SHAKE256 (CRH 64 bytes for tr / mu / rhoprime).
|
|
24
|
+
* ExpandA uses SHAKE128 reading "rho || j || i".
|
|
25
|
+
* ExpandS uses SHAKE256 reading "rhoprime || nonce".
|
|
26
|
+
* ExpandMask uses SHAKE256 reading "rhoprime || (kappa+i)".
|
|
27
|
+
* SampleInBall uses SHAKE256 reading "cTilde".
|
|
28
|
+
*
|
|
29
|
+
* NTT works over Z_q[X]/(X^256 + 1) with q = 8380417 (23 bits) and
|
|
30
|
+
* ζ = 1753 (primitive 512-th root of unity).
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import { sha3 } from '../hash/sha3.js';
|
|
35
|
+
import { bitArray } from '../utils/bitArray.js';
|
|
36
|
+
import { random } from '../utils/random.js';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Byte sizes of every artefact of an ML-DSA parameter set.
|
|
40
|
+
* @typedef {object} MlDsaLengths
|
|
41
|
+
* @property {number} publicKey Public-key length in bytes.
|
|
42
|
+
* @property {number} secretKey Secret-key length in bytes.
|
|
43
|
+
* @property {number} signature Signature length in bytes.
|
|
44
|
+
* @property {number} seed Keygen seed length (32).
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* One ML-DSA parameter-set instance (44 / 65 / 87).
|
|
49
|
+
* @typedef {object} MlDsaInstance
|
|
50
|
+
* @property {MlDsaLengths} lengths Byte sizes of every artefact.
|
|
51
|
+
* @property {(seed?: Uint8Array) => ({ publicKey: Uint8Array, secretKey: Uint8Array }|false)} keygen Generate a key pair (deterministic for a 32-byte seed).
|
|
52
|
+
* @property {(msg: Uint8Array, secretKey: Uint8Array, ctx?: Uint8Array, rnd?: Uint8Array) => (Uint8Array|false)} sign Pure ML-DSA sign.
|
|
53
|
+
* @property {(sig: Uint8Array, msg: Uint8Array, publicKey: Uint8Array, ctx?: Uint8Array) => boolean} verify Pure ML-DSA verify.
|
|
54
|
+
* @property {(msg: Uint8Array, secretKey: Uint8Array, hashAlg: string, hashMod: ({hash: Function, shake?: Function}|Function|null), ctx?: Uint8Array, rnd?: Uint8Array) => (Uint8Array|false)} signPh HashML-DSA sign.
|
|
55
|
+
* @property {(sig: Uint8Array, msg: Uint8Array, publicKey: Uint8Array, hashAlg: string, hashMod: ({hash: Function, shake?: Function}|Function|null), ctx?: Uint8Array) => boolean} verifyPh HashML-DSA verify.
|
|
56
|
+
* @property {{ signInternal: Function, verifyInternal: Function, signWithMu: Function, verifyWithMu: Function, wrapMessage: Function, wrapMessageHash: Function, computePh: Function }} _internal Test-only escape hatches.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Public API returned by `ml_dsa.factory()`.
|
|
61
|
+
* @typedef {object} MlDsaAPI
|
|
62
|
+
* @property {MlDsaInstance} ml_dsa44 ML-DSA-44 instance.
|
|
63
|
+
* @property {MlDsaInstance} ml_dsa65 ML-DSA-65 instance.
|
|
64
|
+
* @property {MlDsaInstance} ml_dsa87 ML-DSA-87 instance.
|
|
65
|
+
* @property {(f: Int32Array) => Int32Array} _ntt Test-only NTT.
|
|
66
|
+
* @property {(f: Int32Array) => Int32Array} _nttInv Test-only inverse NTT.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
export const ml_dsa = {
|
|
70
|
+
name: 'ml_dsa',
|
|
71
|
+
version: '1.0.0',
|
|
72
|
+
type: 'fw.crypto.pkc',
|
|
73
|
+
dependencies: ['sha3', 'bitArray', 'random'],
|
|
74
|
+
deps: [sha3, bitArray, random],
|
|
75
|
+
|
|
76
|
+
/** @returns {MlDsaAPI} */
|
|
77
|
+
factory(sha3, bitArray, random) {
|
|
78
|
+
|
|
79
|
+
const N = 256;
|
|
80
|
+
const Q = 8380417; // 2^23 - 2^13 + 1
|
|
81
|
+
// Q_HALF = (Q-1)>>>1 = 4190208 — FIPS 204 centered representation bound; unused here, kept for spec reference.
|
|
82
|
+
const ROOT = 1753;
|
|
83
|
+
const F_INV = 8347681; // 256^-1 mod Q
|
|
84
|
+
const D = 13;
|
|
85
|
+
const GAMMA2_1 = ((Q - 1) / 88) | 0; // 95232
|
|
86
|
+
const GAMMA2_2 = ((Q - 1) / 32) | 0; // 261888
|
|
87
|
+
|
|
88
|
+
// ── shake / sha3 wrappers ────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
function _shake128(bytes, outBytes) {
|
|
91
|
+
return bitArray.ba_to_ui8(sha3.shake128(bytes, outBytes * 8));
|
|
92
|
+
}
|
|
93
|
+
function _shake256(bytes, outBytes) {
|
|
94
|
+
return bitArray.ba_to_ui8(sha3.shake256(bytes, outBytes * 8));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ── modular arithmetic ───────────────────────────────────────
|
|
98
|
+
|
|
99
|
+
function _mod(a, m) {
|
|
100
|
+
m = m || Q;
|
|
101
|
+
const r = a % m;
|
|
102
|
+
return r < 0 ? r + m : r;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Centered (signed) representative in [-(m-1)/2, m/2].
|
|
106
|
+
function _smod(a, m) {
|
|
107
|
+
m = m || Q;
|
|
108
|
+
const r = _mod(a, m);
|
|
109
|
+
return r > (m >>> 1) ? r - m : r;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ── ζ table for full 256-th NTT (FIPS 204 Appendix B) ────────
|
|
113
|
+
|
|
114
|
+
function _bitRev8(i) {
|
|
115
|
+
let r = 0;
|
|
116
|
+
for (let k = 0; k < 8; k++) r = (r << 1) | ((i >>> k) & 1);
|
|
117
|
+
return r;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const ZETAS = (function () {
|
|
121
|
+
const z = new Int32Array(256);
|
|
122
|
+
for (let i = 0; i < 256; i++) {
|
|
123
|
+
let acc = 1;
|
|
124
|
+
const exp = _bitRev8(i);
|
|
125
|
+
for (let j = 0; j < exp; j++) acc = (acc * ROOT) % Q;
|
|
126
|
+
z[i] = acc;
|
|
127
|
+
}
|
|
128
|
+
return z;
|
|
129
|
+
})();
|
|
130
|
+
|
|
131
|
+
// ── NTT / NTT^-1 (FIPS 204 Algorithms 41 & 42) ───────────────
|
|
132
|
+
|
|
133
|
+
function _ntt(f) {
|
|
134
|
+
let k = 0;
|
|
135
|
+
for (let len = 128; len >= 1; len >>>= 1) {
|
|
136
|
+
for (let start = 0; start < N; start += 2 * len) {
|
|
137
|
+
k++;
|
|
138
|
+
const zeta = ZETAS[k];
|
|
139
|
+
for (let j = start; j < start + len; j++) {
|
|
140
|
+
const t = (zeta * f[j + len]) % Q;
|
|
141
|
+
f[j + len] = _mod(f[j] - t);
|
|
142
|
+
f[j] = _mod(f[j] + t);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return f;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function _nttInv(f) {
|
|
150
|
+
let k = 256;
|
|
151
|
+
for (let len = 1; len <= 128; len <<= 1) {
|
|
152
|
+
for (let start = 0; start < N; start += 2 * len) {
|
|
153
|
+
k--;
|
|
154
|
+
const zeta = -ZETAS[k];
|
|
155
|
+
for (let j = start; j < start + len; j++) {
|
|
156
|
+
const t = f[j];
|
|
157
|
+
f[j] = _mod(t + f[j + len]);
|
|
158
|
+
f[j + len] = (zeta * (t - f[j + len])) % Q;
|
|
159
|
+
f[j + len] = _mod(f[j + len]);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
for (let i = 0; i < N; i++) f[i] = _mod(F_INV * f[i]);
|
|
164
|
+
return f;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Pointwise product in NTT domain (full 256-th roots, no base case).
|
|
168
|
+
function _multiplyNTTs(out, a, b) {
|
|
169
|
+
for (let i = 0; i < N; i++) out[i] = _mod(a[i] * b[i]);
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function _polyAdd(a, b) {
|
|
174
|
+
for (let i = 0; i < N; i++) a[i] = _mod(a[i] + b[i]);
|
|
175
|
+
return a;
|
|
176
|
+
}
|
|
177
|
+
function _polySub(a, b) {
|
|
178
|
+
for (let i = 0; i < N; i++) a[i] = _mod(a[i] - b[i]);
|
|
179
|
+
return a;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// L∞-norm check on centered representatives.
|
|
183
|
+
function _polyChknorm(p, B) {
|
|
184
|
+
for (let i = 0; i < N; i++) {
|
|
185
|
+
const v = _smod(p[i]);
|
|
186
|
+
if ((v < 0 ? -v : v) >= B) return true;
|
|
187
|
+
}
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ── Power2Round / Decompose / MakeHint / UseHint ─────────────
|
|
192
|
+
|
|
193
|
+
const D_POW = 1 << D; // 8192
|
|
194
|
+
const D_HALF = 1 << (D - 1); // 4096
|
|
195
|
+
|
|
196
|
+
function _power2Round(r) {
|
|
197
|
+
const rPlus = _mod(r);
|
|
198
|
+
const r0 = _smod(rPlus, D_POW);
|
|
199
|
+
return { r1: ((rPlus - r0) / D_POW) | 0, r0 };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function _decompose(r, gamma2) {
|
|
203
|
+
const rPlus = _mod(r);
|
|
204
|
+
let r0 = _smod(rPlus, 2 * gamma2);
|
|
205
|
+
if (rPlus - r0 === Q - 1) return { r1: 0, r0: r0 - 1 };
|
|
206
|
+
return { r1: ((rPlus - r0) / (2 * gamma2)) | 0, r0 };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function _highBits(r, gamma2) { return _decompose(r, gamma2).r1; }
|
|
210
|
+
function _lowBits(r, gamma2) { return _decompose(r, gamma2).r0; }
|
|
211
|
+
|
|
212
|
+
// FIPS 204 Algorithm 39 (Dilithium reference variant on transformed inputs).
|
|
213
|
+
function _makeHint(z, r, gamma2) {
|
|
214
|
+
return (z <= gamma2 || z > Q - gamma2 || (z === Q - gamma2 && r === 0)) ? 0 : 1;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function _useHint(h, r, gamma2) {
|
|
218
|
+
const m = ((Q - 1) / (2 * gamma2)) | 0;
|
|
219
|
+
const { r1, r0 } = _decompose(r, gamma2);
|
|
220
|
+
if (h === 1) return r0 > 0 ? _mod(r1 + 1, m) : _mod(r1 - 1, m);
|
|
221
|
+
return r1;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ── bit packers ──────────────────────────────────────────────
|
|
225
|
+
// Pack 256 d-bit words (LE) → 32*d bytes.
|
|
226
|
+
|
|
227
|
+
function _packBits(values, d) {
|
|
228
|
+
const out = new Uint8Array(32 * d);
|
|
229
|
+
const mask = (1 << d) - 1;
|
|
230
|
+
let buf = 0, bufLen = 0, pos = 0;
|
|
231
|
+
for (let i = 0; i < values.length; i++) {
|
|
232
|
+
buf |= (values[i] & mask) << bufLen;
|
|
233
|
+
bufLen += d;
|
|
234
|
+
while (bufLen >= 8) {
|
|
235
|
+
out[pos++] = buf & 0xff;
|
|
236
|
+
buf >>>= 8;
|
|
237
|
+
bufLen -= 8;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return out;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function _unpackBits(bytes, d) {
|
|
244
|
+
const out = new Int32Array(N);
|
|
245
|
+
const mask = (1 << d) - 1;
|
|
246
|
+
let buf = 0, bufLen = 0, pos = 0;
|
|
247
|
+
for (let i = 0; i < bytes.length && pos < N; i++) {
|
|
248
|
+
buf |= bytes[i] << bufLen;
|
|
249
|
+
bufLen += 8;
|
|
250
|
+
while (bufLen >= d && pos < N) {
|
|
251
|
+
out[pos++] = buf & mask;
|
|
252
|
+
buf >>>= d;
|
|
253
|
+
bufLen -= d;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// SimpleBitPack / BitPack with maps (FIPS 204 §7).
|
|
260
|
+
|
|
261
|
+
function _packETA(p, eta) {
|
|
262
|
+
// map: x ∈ [-eta, eta] → eta - x ∈ [0, 2*eta]
|
|
263
|
+
const tmp = new Int32Array(N);
|
|
264
|
+
for (let i = 0; i < N; i++) tmp[i] = eta - _smod(p[i]);
|
|
265
|
+
return _packBits(tmp, eta === 2 ? 3 : 4);
|
|
266
|
+
}
|
|
267
|
+
function _unpackETA(b, eta) {
|
|
268
|
+
const raw = _unpackBits(b, eta === 2 ? 3 : 4);
|
|
269
|
+
const out = new Int32Array(N);
|
|
270
|
+
for (let i = 0; i < N; i++) out[i] = _mod(eta - raw[i]);
|
|
271
|
+
return out;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function _packT0(p) {
|
|
275
|
+
// map: x ∈ (-2^12, 2^12] → 2^12 - x ∈ [0, 2^13)
|
|
276
|
+
const tmp = new Int32Array(N);
|
|
277
|
+
for (let i = 0; i < N; i++) tmp[i] = D_HALF - _smod(p[i]);
|
|
278
|
+
return _packBits(tmp, 13);
|
|
279
|
+
}
|
|
280
|
+
function _unpackT0(b) {
|
|
281
|
+
const raw = _unpackBits(b, 13);
|
|
282
|
+
const out = new Int32Array(N);
|
|
283
|
+
for (let i = 0; i < N; i++) out[i] = _mod(D_HALF - raw[i]);
|
|
284
|
+
return out;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function _packT1(p) { return _packBits(p, 10); }
|
|
288
|
+
function _unpackT1(b) { return _unpackBits(b, 10); }
|
|
289
|
+
|
|
290
|
+
function _packZ(p, gamma1) {
|
|
291
|
+
const d = gamma1 === (1 << 17) ? 18 : 20;
|
|
292
|
+
const tmp = new Int32Array(N);
|
|
293
|
+
for (let i = 0; i < N; i++) tmp[i] = gamma1 - _smod(p[i]);
|
|
294
|
+
return _packBits(tmp, d);
|
|
295
|
+
}
|
|
296
|
+
function _unpackZ(b, gamma1) {
|
|
297
|
+
const d = gamma1 === (1 << 17) ? 18 : 20;
|
|
298
|
+
const raw = _unpackBits(b, d);
|
|
299
|
+
const out = new Int32Array(N);
|
|
300
|
+
for (let i = 0; i < N; i++) out[i] = _mod(gamma1 - raw[i]);
|
|
301
|
+
return out;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function _packW1(p, gamma2) {
|
|
305
|
+
const d = gamma2 === GAMMA2_1 ? 6 : 4;
|
|
306
|
+
return _packBits(p, d);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// ── Sampling primitives ──────────────────────────────────────
|
|
310
|
+
|
|
311
|
+
// FIPS 204 Algorithm 14: RejNTTPoly. Read 3 bytes at a time, accept t < Q.
|
|
312
|
+
const _XOF128_BYTES = 5184; // 31 SHAKE128 blocks (168·31). Empirically safe.
|
|
313
|
+
|
|
314
|
+
function _rejNTTPoly(rho, j, i) {
|
|
315
|
+
const inp = new Uint8Array(rho.length + 2);
|
|
316
|
+
inp.set(rho, 0);
|
|
317
|
+
inp[rho.length] = j;
|
|
318
|
+
inp[rho.length + 1] = i;
|
|
319
|
+
let buf = _shake128(inp, _XOF128_BYTES);
|
|
320
|
+
const out = new Int32Array(N);
|
|
321
|
+
let pos = 0;
|
|
322
|
+
for (let k = 0; k + 3 <= buf.length && pos < N; k += 3) {
|
|
323
|
+
const t = (buf[k] | (buf[k + 1] << 8) | (buf[k + 2] << 16)) & 0x7fffff;
|
|
324
|
+
if (t < Q) out[pos++] = t;
|
|
325
|
+
}
|
|
326
|
+
if (pos < N) {
|
|
327
|
+
buf = _shake128(inp, _XOF128_BYTES * 4);
|
|
328
|
+
pos = 0;
|
|
329
|
+
for (let k = 0; k + 3 <= buf.length && pos < N; k += 3) {
|
|
330
|
+
const t = (buf[k] | (buf[k + 1] << 8) | (buf[k + 2] << 16)) & 0x7fffff;
|
|
331
|
+
if (t < Q) out[pos++] = t;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return out;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// FIPS 204 Algorithm 15: RejBoundedPoly using ExpandS.
|
|
338
|
+
const _XOF256_BYTES = 1632; // 12 SHAKE256 blocks.
|
|
339
|
+
|
|
340
|
+
// Returns null on reject - a number sentinel (e.g. -1) would collide
|
|
341
|
+
// with the valid η=4, nibble=5 coefficient 4-5 = -1.
|
|
342
|
+
function _coefFromHalfByte(n, eta) {
|
|
343
|
+
if (eta === 2) return n < 15 ? 2 - (n % 5) : null;
|
|
344
|
+
return n < 9 ? 4 - n : null;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function _rejBoundedPoly(rhoPrime, nonce, eta) {
|
|
348
|
+
const inp = new Uint8Array(rhoPrime.length + 2);
|
|
349
|
+
inp.set(rhoPrime, 0);
|
|
350
|
+
inp[rhoPrime.length] = nonce & 0xff;
|
|
351
|
+
inp[rhoPrime.length + 1] = (nonce >>> 8) & 0xff;
|
|
352
|
+
let buf = _shake256(inp, _XOF256_BYTES);
|
|
353
|
+
const out = new Int32Array(N);
|
|
354
|
+
let pos = 0;
|
|
355
|
+
for (let k = 0; k < buf.length && pos < N; k++) {
|
|
356
|
+
const d1 = _coefFromHalfByte(buf[k] & 0x0f, eta);
|
|
357
|
+
const d2 = _coefFromHalfByte((buf[k] >>> 4) & 0x0f, eta);
|
|
358
|
+
if (d1 !== null) out[pos++] = _mod(d1);
|
|
359
|
+
if (pos < N && d2 !== null) out[pos++] = _mod(d2);
|
|
360
|
+
}
|
|
361
|
+
if (pos < N) {
|
|
362
|
+
buf = _shake256(inp, _XOF256_BYTES * 4);
|
|
363
|
+
pos = 0;
|
|
364
|
+
for (let k = 0; k < buf.length && pos < N; k++) {
|
|
365
|
+
const d1 = _coefFromHalfByte(buf[k] & 0x0f, eta);
|
|
366
|
+
const d2 = _coefFromHalfByte((buf[k] >>> 4) & 0x0f, eta);
|
|
367
|
+
if (d1 !== null) out[pos++] = _mod(d1);
|
|
368
|
+
if (pos < N && d2 !== null) out[pos++] = _mod(d2);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return out;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// FIPS 204 Algorithm 34: ExpandMask. One ZCoder polynomial per L row.
|
|
375
|
+
function _expandMask(rhoPrime, kappa_i, gamma1) {
|
|
376
|
+
const d = gamma1 === (1 << 17) ? 18 : 20;
|
|
377
|
+
const bytesLen = 32 * d;
|
|
378
|
+
const inp = new Uint8Array(rhoPrime.length + 2);
|
|
379
|
+
inp.set(rhoPrime, 0);
|
|
380
|
+
inp[rhoPrime.length] = kappa_i & 0xff;
|
|
381
|
+
inp[rhoPrime.length + 1] = (kappa_i >>> 8) & 0xff;
|
|
382
|
+
const buf = _shake256(inp, bytesLen);
|
|
383
|
+
return _unpackZ(buf, gamma1);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// FIPS 204 Algorithm 29: SampleInBall.
|
|
387
|
+
function _sampleInBall(cTilde, tau) {
|
|
388
|
+
// Need first 8 bytes for sign mask, then rejection-sampled positions.
|
|
389
|
+
// Worst-case bytes for tau=60, N=256 well under 4 KiB.
|
|
390
|
+
const buf = _shake256(cTilde, 4096);
|
|
391
|
+
const c = new Int32Array(N);
|
|
392
|
+
const masks = buf.subarray(0, 8);
|
|
393
|
+
let pos = 8, maskBit = 0, maskByte = 0;
|
|
394
|
+
for (let i = N - tau; i < N; i++) {
|
|
395
|
+
let b = i + 1;
|
|
396
|
+
while (b > i) {
|
|
397
|
+
if (pos >= buf.length) {
|
|
398
|
+
console.error('[crypto] BUG: ml_dsa: SampleInBall buffer exhausted');
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
b = buf[pos++];
|
|
402
|
+
}
|
|
403
|
+
c[i] = c[b];
|
|
404
|
+
c[b] = 1 - (((masks[maskByte] >>> maskBit) & 1) << 1);
|
|
405
|
+
maskBit++;
|
|
406
|
+
if (maskBit >= 8) { maskBit = 0; maskByte++; }
|
|
407
|
+
}
|
|
408
|
+
return c;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// ── ML-DSA core (parameterised) ──────────────────────────────
|
|
412
|
+
|
|
413
|
+
function _make(P) {
|
|
414
|
+
const { K, L, GAMMA1, GAMMA2, TAU, ETA, OMEGA, C_TILDE_BYTES } = P;
|
|
415
|
+
const TR_BYTES = 64;
|
|
416
|
+
const CRH_BYTES = 64;
|
|
417
|
+
const BETA = TAU * ETA;
|
|
418
|
+
const Z_BYTES = 32 * (GAMMA1 === (1 << 17) ? 18 : 20);
|
|
419
|
+
const W1_BYTES = 32 * (GAMMA2 === GAMMA2_1 ? 6 : 4);
|
|
420
|
+
const ETA_D = ETA === 2 ? 3 : 4;
|
|
421
|
+
const SK_S_LEN = 32 * ETA_D;
|
|
422
|
+
|
|
423
|
+
const PK_LEN = 32 + K * 32 * 10; // rho || pkT1
|
|
424
|
+
const SK_LEN = 32 + 32 + TR_BYTES + L * SK_S_LEN + K * SK_S_LEN + K * 32 * 13;
|
|
425
|
+
const SIG_LEN = C_TILDE_BYTES + L * Z_BYTES + (OMEGA + K);
|
|
426
|
+
|
|
427
|
+
// ── encode/decode high-level structures ──────────────────
|
|
428
|
+
|
|
429
|
+
function _encodePK(rho, t1) {
|
|
430
|
+
const out = new Uint8Array(PK_LEN);
|
|
431
|
+
out.set(rho, 0);
|
|
432
|
+
for (let i = 0; i < K; i++) out.set(_packT1(t1[i]), 32 + i * 320);
|
|
433
|
+
return out;
|
|
434
|
+
}
|
|
435
|
+
function _decodePK(pk) {
|
|
436
|
+
const rho = pk.subarray(0, 32);
|
|
437
|
+
const t1 = new Array(K);
|
|
438
|
+
for (let i = 0; i < K; i++) t1[i] = _unpackT1(pk.subarray(32 + i * 320, 32 + (i + 1) * 320));
|
|
439
|
+
return { rho, t1 };
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function _encodeSK(rho, K_, tr, s1, s2, t0) {
|
|
443
|
+
const out = new Uint8Array(SK_LEN);
|
|
444
|
+
let off = 0;
|
|
445
|
+
out.set(rho, off); off += 32;
|
|
446
|
+
out.set(K_, off); off += 32;
|
|
447
|
+
out.set(tr, off); off += TR_BYTES;
|
|
448
|
+
for (let i = 0; i < L; i++) { out.set(_packETA(s1[i], ETA), off); off += SK_S_LEN; }
|
|
449
|
+
for (let i = 0; i < K; i++) { out.set(_packETA(s2[i], ETA), off); off += SK_S_LEN; }
|
|
450
|
+
for (let i = 0; i < K; i++) { out.set(_packT0(t0[i]), off); off += 32 * 13; }
|
|
451
|
+
return out;
|
|
452
|
+
}
|
|
453
|
+
function _decodeSK(sk) {
|
|
454
|
+
let off = 0;
|
|
455
|
+
const rho = sk.subarray(off, off + 32); off += 32;
|
|
456
|
+
const K_ = sk.subarray(off, off + 32); off += 32;
|
|
457
|
+
const tr = sk.subarray(off, off + TR_BYTES); off += TR_BYTES;
|
|
458
|
+
const s1 = new Array(L);
|
|
459
|
+
for (let i = 0; i < L; i++) { s1[i] = _unpackETA(sk.subarray(off, off + SK_S_LEN), ETA); off += SK_S_LEN; }
|
|
460
|
+
const s2 = new Array(K);
|
|
461
|
+
for (let i = 0; i < K; i++) { s2[i] = _unpackETA(sk.subarray(off, off + SK_S_LEN), ETA); off += SK_S_LEN; }
|
|
462
|
+
const t0 = new Array(K);
|
|
463
|
+
for (let i = 0; i < K; i++) { t0[i] = _unpackT0(sk.subarray(off, off + 32 * 13)); off += 32 * 13; }
|
|
464
|
+
return { rho, K_, tr, s1, s2, t0 };
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function _encodeHint(h) {
|
|
468
|
+
const out = new Uint8Array(OMEGA + K);
|
|
469
|
+
let k = 0;
|
|
470
|
+
for (let i = 0; i < K; i++) {
|
|
471
|
+
for (let j = 0; j < N; j++) if (h[i][j] !== 0) out[k++] = j;
|
|
472
|
+
out[OMEGA + i] = k;
|
|
473
|
+
}
|
|
474
|
+
return out;
|
|
475
|
+
}
|
|
476
|
+
function _decodeHint(buf) {
|
|
477
|
+
const h = new Array(K);
|
|
478
|
+
let k = 0;
|
|
479
|
+
for (let i = 0; i < K; i++) {
|
|
480
|
+
const hi = new Int32Array(N);
|
|
481
|
+
if (buf[OMEGA + i] < k || buf[OMEGA + i] > OMEGA) return false;
|
|
482
|
+
for (let j = k; j < buf[OMEGA + i]; j++) {
|
|
483
|
+
if (j > k && buf[j] <= buf[j - 1]) return false;
|
|
484
|
+
hi[buf[j]] = 1;
|
|
485
|
+
}
|
|
486
|
+
k = buf[OMEGA + i];
|
|
487
|
+
h[i] = hi;
|
|
488
|
+
}
|
|
489
|
+
for (let j = k; j < OMEGA; j++) if (buf[j] !== 0) return false;
|
|
490
|
+
return h;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function _encodeSig(cTilde, z, h) {
|
|
494
|
+
const out = new Uint8Array(SIG_LEN);
|
|
495
|
+
out.set(cTilde, 0);
|
|
496
|
+
let off = C_TILDE_BYTES;
|
|
497
|
+
for (let i = 0; i < L; i++) { out.set(_packZ(z[i], GAMMA1), off); off += Z_BYTES; }
|
|
498
|
+
out.set(_encodeHint(h), off);
|
|
499
|
+
return out;
|
|
500
|
+
}
|
|
501
|
+
function _decodeSig(sig) {
|
|
502
|
+
const cTilde = sig.subarray(0, C_TILDE_BYTES);
|
|
503
|
+
const z = new Array(L);
|
|
504
|
+
let off = C_TILDE_BYTES;
|
|
505
|
+
for (let i = 0; i < L; i++) { z[i] = _unpackZ(sig.subarray(off, off + Z_BYTES), GAMMA1); off += Z_BYTES; }
|
|
506
|
+
const h = _decodeHint(sig.subarray(off));
|
|
507
|
+
return { cTilde, z, h };
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// ── keygen (FIPS 204 Algorithm 1 / §6.1) ────────────────
|
|
511
|
+
|
|
512
|
+
function keygen(seed) {
|
|
513
|
+
if (seed && seed.length !== 32) {
|
|
514
|
+
console.warn('[crypto] INVALID: ml_dsa: seed must be 32 bytes');
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
const _seed = seed || random.bytes(32);
|
|
518
|
+
const seedDst = new Uint8Array(34);
|
|
519
|
+
seedDst.set(_seed, 0);
|
|
520
|
+
seedDst[32] = K;
|
|
521
|
+
seedDst[33] = L;
|
|
522
|
+
const expanded = _shake256(seedDst, 128); // (rho, rhoprime, K)
|
|
523
|
+
const rho = expanded.subarray(0, 32);
|
|
524
|
+
const rhoPrime = expanded.subarray(32, 96);
|
|
525
|
+
const K_ = expanded.subarray(96, 128);
|
|
526
|
+
|
|
527
|
+
const s1 = new Array(L);
|
|
528
|
+
for (let i = 0; i < L; i++) s1[i] = _rejBoundedPoly(rhoPrime, i, ETA);
|
|
529
|
+
const s2 = new Array(K);
|
|
530
|
+
for (let i = 0; i < K; i++) s2[i] = _rejBoundedPoly(rhoPrime, L + i, ETA);
|
|
531
|
+
|
|
532
|
+
const s1Hat = new Array(L);
|
|
533
|
+
for (let i = 0; i < L; i++) {
|
|
534
|
+
s1Hat[i] = new Int32Array(s1[i]);
|
|
535
|
+
_ntt(s1Hat[i]);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const t0 = new Array(K);
|
|
539
|
+
const t1 = new Array(K);
|
|
540
|
+
const tmp = new Int32Array(N);
|
|
541
|
+
for (let i = 0; i < K; i++) {
|
|
542
|
+
const t = new Int32Array(N);
|
|
543
|
+
for (let j = 0; j < L; j++) {
|
|
544
|
+
const aij = _rejNTTPoly(rho, j, i);
|
|
545
|
+
_multiplyNTTs(tmp, aij, s1Hat[j]);
|
|
546
|
+
_polyAdd(t, tmp);
|
|
547
|
+
}
|
|
548
|
+
_nttInv(t);
|
|
549
|
+
_polyAdd(t, s2[i]);
|
|
550
|
+
const r0 = new Int32Array(N), r1 = new Int32Array(N);
|
|
551
|
+
for (let k = 0; k < N; k++) {
|
|
552
|
+
const pr = _power2Round(t[k]);
|
|
553
|
+
r0[k] = pr.r0; r1[k] = pr.r1;
|
|
554
|
+
}
|
|
555
|
+
t0[i] = r0; t1[i] = r1;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
const publicKey = _encodePK(rho, t1);
|
|
559
|
+
const tr = _shake256(publicKey, TR_BYTES);
|
|
560
|
+
const secretKey = _encodeSK(rho, K_, tr, s1, s2, t0);
|
|
561
|
+
return { publicKey, secretKey };
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// ── prefix message with FIPS 204 §5.4 wrapper ───────────
|
|
565
|
+
|
|
566
|
+
function _wrapMessage(msg, ctx) {
|
|
567
|
+
const _ctx = ctx || new Uint8Array(0);
|
|
568
|
+
if (_ctx.length > 255) {
|
|
569
|
+
console.warn('[crypto] INVALID: ml_dsa: context too long');
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
const out = new Uint8Array(2 + _ctx.length + msg.length);
|
|
573
|
+
out[0] = 0;
|
|
574
|
+
out[1] = _ctx.length;
|
|
575
|
+
out.set(_ctx, 2);
|
|
576
|
+
out.set(msg, 2 + _ctx.length);
|
|
577
|
+
return out;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// ── HashML-DSA wrapper (FIPS 204 §5.4 Algorithm 4) ──────────
|
|
581
|
+
// Iteration E3 of the FIPS 140-3 upgrade plan.
|
|
582
|
+
//
|
|
583
|
+
// M' = 0x01 || OctetEncode(|ctx|, 1) || ctx || OID(hashAlg) || PH(message)
|
|
584
|
+
//
|
|
585
|
+
// OID is the DER-encoded ASN.1 OBJECT IDENTIFIER of the hash
|
|
586
|
+
// function (11 bytes : 06 09 60 86 48 01 65 03 04 02 XX).
|
|
587
|
+
|
|
588
|
+
// Hash algorithm names match ACVP convention (mixed `SHA2-`, `SHA-`,
|
|
589
|
+
// `SHA3-`, `SHAKE-` prefixes - mirror as-is for byte-exact ACVP
|
|
590
|
+
// replay compatibility).
|
|
591
|
+
const _HASH_OIDS = {
|
|
592
|
+
'SHA2-224': new Uint8Array([0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x04]),
|
|
593
|
+
'SHA2-256': new Uint8Array([0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x01]),
|
|
594
|
+
'SHA2-384': new Uint8Array([0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x02]),
|
|
595
|
+
'SHA2-512': new Uint8Array([0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x03]),
|
|
596
|
+
'SHA2-512/224': new Uint8Array([0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x05]),
|
|
597
|
+
'SHA2-512/256': new Uint8Array([0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x06]),
|
|
598
|
+
'SHA3-224': new Uint8Array([0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x07]),
|
|
599
|
+
'SHA3-256': new Uint8Array([0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x08]),
|
|
600
|
+
'SHA3-384': new Uint8Array([0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x09]),
|
|
601
|
+
'SHA3-512': new Uint8Array([0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x0A]),
|
|
602
|
+
'SHAKE-128': new Uint8Array([0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x0B]),
|
|
603
|
+
'SHAKE-256': new Uint8Array([0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x0C]),
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
// Caller provides the prehash bytes (PH(message) per FIPS 204
|
|
607
|
+
// §5.4.1). The function builds the OID-prefixed wrapper M'.
|
|
608
|
+
// Validation of `prehash.length` against `hashAlg` is the
|
|
609
|
+
// caller's responsibility (HashML-DSA accepts variable digest
|
|
610
|
+
// sizes per hashAlg).
|
|
611
|
+
function _wrapMessageHash(prehash, ctx, hashAlg) {
|
|
612
|
+
const _ctx = ctx || new Uint8Array(0);
|
|
613
|
+
if (_ctx.length > 255) {
|
|
614
|
+
console.warn('[crypto] INVALID: ml_dsa: context too long');
|
|
615
|
+
return false;
|
|
616
|
+
}
|
|
617
|
+
const oid = _HASH_OIDS[hashAlg];
|
|
618
|
+
if (!oid) {
|
|
619
|
+
console.warn('[crypto] INVALID: ml_dsa: unknown hashAlg "' + hashAlg + '"');
|
|
620
|
+
return false;
|
|
621
|
+
}
|
|
622
|
+
const out = new Uint8Array(2 + _ctx.length + oid.length + prehash.length);
|
|
623
|
+
out[0] = 1; // 0x01 = HashML-DSA discriminator
|
|
624
|
+
out[1] = _ctx.length;
|
|
625
|
+
out.set(_ctx, 2);
|
|
626
|
+
out.set(oid, 2 + _ctx.length);
|
|
627
|
+
out.set(prehash, 2 + _ctx.length + oid.length);
|
|
628
|
+
return out;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// ── sign (FIPS 204 Algorithm 2 / §6.2) ──────────────────
|
|
632
|
+
|
|
633
|
+
// Iteration E3 of the FIPS 140-3 upgrade plan - sign refactor:
|
|
634
|
+
// extract `_signFromMu(mu, sk, rnd)` so callers may bypass the
|
|
635
|
+
// §5.4 wrapping (internal interface) or supply a pre-computed mu
|
|
636
|
+
// (externalMu, useful when the same key signs many messages with
|
|
637
|
+
// a shared `tr`-based prefix).
|
|
638
|
+
//
|
|
639
|
+
// ## Rejection-loop side-channel posture (FIPS 204 §5.6 step 23+)
|
|
640
|
+
//
|
|
641
|
+
// The loop body performs deterministic NTT / scalar operations
|
|
642
|
+
// and uses `_polyChknorm` to test whether the candidate (z, r0,
|
|
643
|
+
// ct0, hint count) lies in the valid range. The `break`/`continue`
|
|
644
|
+
// statements leak ONLY the rejection event itself - i.e. the
|
|
645
|
+
// **number of iterations** before success - which is the
|
|
646
|
+
// unavoidable timing signal inherent to FIPS 204 rejection
|
|
647
|
+
// sampling. No additional secret-dependent branches happen
|
|
648
|
+
// inside one iteration: every byte of the NTT polynomials is
|
|
649
|
+
// touched on every loop pass, and the secret s1Hat / s2Hat / t0Hat
|
|
650
|
+
// are consumed in fixed-iteration `_multiplyNTTs` calls.
|
|
651
|
+
// This matches the reference implementation's posture; see
|
|
652
|
+
// FIPS 204 §A.3 (informational side-channel discussion).
|
|
653
|
+
function _signFromMu(mu, secretKey, rnd) {
|
|
654
|
+
if (!(mu instanceof Uint8Array) || mu.length !== CRH_BYTES) {
|
|
655
|
+
console.warn('[crypto] INVALID: ml_dsa: mu must be ' + CRH_BYTES + ' bytes');
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
if (secretKey.length !== SK_LEN) {
|
|
659
|
+
console.warn('[crypto] INVALID: ml_dsa: wrong secretKey length');
|
|
660
|
+
return false;
|
|
661
|
+
}
|
|
662
|
+
const _rnd = rnd || new Uint8Array(32);
|
|
663
|
+
if (_rnd.length !== 32) {
|
|
664
|
+
console.warn('[crypto] INVALID: ml_dsa: rnd must be 32 bytes');
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const { rho, K_, s1, s2, t0 } = _decodeSK(secretKey);
|
|
669
|
+
// Cache A in NTT.
|
|
670
|
+
const A = new Array(K);
|
|
671
|
+
for (let i = 0; i < K; i++) {
|
|
672
|
+
A[i] = new Array(L);
|
|
673
|
+
for (let j = 0; j < L; j++) A[i][j] = _rejNTTPoly(rho, j, i);
|
|
674
|
+
}
|
|
675
|
+
const s1Hat = new Array(L);
|
|
676
|
+
for (let i = 0; i < L; i++) { s1Hat[i] = new Int32Array(s1[i]); _ntt(s1Hat[i]); }
|
|
677
|
+
const s2Hat = new Array(K);
|
|
678
|
+
for (let i = 0; i < K; i++) { s2Hat[i] = new Int32Array(s2[i]); _ntt(s2Hat[i]); }
|
|
679
|
+
const t0Hat = new Array(K);
|
|
680
|
+
for (let i = 0; i < K; i++) { t0Hat[i] = new Int32Array(t0[i]); _ntt(t0Hat[i]); }
|
|
681
|
+
|
|
682
|
+
// rhoprime = SHAKE256(K || rnd || mu, 64)
|
|
683
|
+
const rpIn = new Uint8Array(32 + 32 + CRH_BYTES);
|
|
684
|
+
rpIn.set(K_, 0); rpIn.set(_rnd, 32); rpIn.set(mu, 64);
|
|
685
|
+
const rhoPrime = _shake256(rpIn, CRH_BYTES);
|
|
686
|
+
|
|
687
|
+
let kappa = 0;
|
|
688
|
+
const tmp = new Int32Array(N);
|
|
689
|
+
for (let attempt = 0; attempt < 1000; attempt++) {
|
|
690
|
+
// y = ExpandMask(rhoPrime, kappa..kappa+L-1)
|
|
691
|
+
const y = new Array(L);
|
|
692
|
+
for (let i = 0; i < L; i++) y[i] = _expandMask(rhoPrime, kappa + i, GAMMA1);
|
|
693
|
+
// z_ntt = NTT(y) - copies needed since we mutate
|
|
694
|
+
const yHat = new Array(L);
|
|
695
|
+
for (let i = 0; i < L; i++) { yHat[i] = new Int32Array(y[i]); _ntt(yHat[i]); }
|
|
696
|
+
// w = NTT^-1(A * yHat)
|
|
697
|
+
const w = new Array(K);
|
|
698
|
+
for (let i = 0; i < K; i++) {
|
|
699
|
+
const wi = new Int32Array(N);
|
|
700
|
+
for (let j = 0; j < L; j++) {
|
|
701
|
+
_multiplyNTTs(tmp, A[i][j], yHat[j]);
|
|
702
|
+
_polyAdd(wi, tmp);
|
|
703
|
+
}
|
|
704
|
+
_nttInv(wi);
|
|
705
|
+
w[i] = wi;
|
|
706
|
+
}
|
|
707
|
+
const w1 = new Array(K);
|
|
708
|
+
for (let i = 0; i < K; i++) {
|
|
709
|
+
w1[i] = new Int32Array(N);
|
|
710
|
+
for (let k = 0; k < N; k++) w1[i][k] = _highBits(w[i][k], GAMMA2);
|
|
711
|
+
}
|
|
712
|
+
// cTilde = SHAKE256(mu || w1Encode, 2λ)
|
|
713
|
+
const w1Bytes = new Uint8Array(K * W1_BYTES);
|
|
714
|
+
for (let i = 0; i < K; i++) w1Bytes.set(_packW1(w1[i], GAMMA2), i * W1_BYTES);
|
|
715
|
+
const cIn = new Uint8Array(CRH_BYTES + w1Bytes.length);
|
|
716
|
+
cIn.set(mu, 0); cIn.set(w1Bytes, CRH_BYTES);
|
|
717
|
+
const cTilde = _shake256(cIn, C_TILDE_BYTES);
|
|
718
|
+
|
|
719
|
+
const c = _sampleInBall(cTilde, TAU);
|
|
720
|
+
if (c === false) return false;
|
|
721
|
+
const cHat = new Int32Array(c); _ntt(cHat);
|
|
722
|
+
|
|
723
|
+
// z = y + NTT^-1(cHat * s1Hat)
|
|
724
|
+
const z = new Array(L);
|
|
725
|
+
let bad = false;
|
|
726
|
+
for (let i = 0; i < L; i++) {
|
|
727
|
+
const cs1 = new Int32Array(N);
|
|
728
|
+
_multiplyNTTs(cs1, cHat, s1Hat[i]);
|
|
729
|
+
_nttInv(cs1);
|
|
730
|
+
_polyAdd(cs1, y[i]);
|
|
731
|
+
if (_polyChknorm(cs1, GAMMA1 - BETA)) { bad = true; break; }
|
|
732
|
+
z[i] = cs1;
|
|
733
|
+
}
|
|
734
|
+
if (bad) { kappa += L; continue; }
|
|
735
|
+
|
|
736
|
+
// r0 = LowBits(w - NTT^-1(cHat * s2Hat)); ct0 = NTT^-1(cHat * t0Hat)
|
|
737
|
+
let cnt = 0;
|
|
738
|
+
const h = new Array(K);
|
|
739
|
+
let validRound = true;
|
|
740
|
+
for (let i = 0; i < K; i++) {
|
|
741
|
+
const cs2 = new Int32Array(N);
|
|
742
|
+
_multiplyNTTs(cs2, cHat, s2Hat[i]);
|
|
743
|
+
_nttInv(cs2);
|
|
744
|
+
const wMinusCs2 = new Int32Array(w[i]);
|
|
745
|
+
_polySub(wMinusCs2, cs2);
|
|
746
|
+
const r0 = new Int32Array(N);
|
|
747
|
+
for (let k = 0; k < N; k++) r0[k] = _lowBits(wMinusCs2[k], GAMMA2);
|
|
748
|
+
if (_polyChknorm(r0, GAMMA2 - BETA)) { validRound = false; break; }
|
|
749
|
+
|
|
750
|
+
const ct0 = new Int32Array(N);
|
|
751
|
+
_multiplyNTTs(ct0, cHat, t0Hat[i]);
|
|
752
|
+
_nttInv(ct0);
|
|
753
|
+
if (_polyChknorm(ct0, GAMMA2)) { validRound = false; break; }
|
|
754
|
+
|
|
755
|
+
// r0' = r0 + ct0 (mod q, signed)
|
|
756
|
+
const r0p = new Int32Array(N);
|
|
757
|
+
for (let k = 0; k < N; k++) r0p[k] = _mod(r0[k] + ct0[k]);
|
|
758
|
+
|
|
759
|
+
// hint at position k = MakeHint(r0p[k], w1[i][k])
|
|
760
|
+
const hi = new Int32Array(N);
|
|
761
|
+
for (let k = 0; k < N; k++) {
|
|
762
|
+
hi[k] = _makeHint(r0p[k], w1[i][k], GAMMA2);
|
|
763
|
+
cnt += hi[k];
|
|
764
|
+
}
|
|
765
|
+
h[i] = hi;
|
|
766
|
+
}
|
|
767
|
+
if (!validRound) { kappa += L; continue; }
|
|
768
|
+
if (cnt > OMEGA) { kappa += L; continue; }
|
|
769
|
+
|
|
770
|
+
return _encodeSig(cTilde, z, h);
|
|
771
|
+
}
|
|
772
|
+
console.error('[crypto] BUG: ml_dsa: signing exceeded retry budget');
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// Compute mu = SHAKE256(tr || M, CRH_BYTES) and call _signFromMu.
|
|
777
|
+
// M is the (already prepared) message bytes - caller is
|
|
778
|
+
// responsible for the FIPS 204 §5.4 wrapper.
|
|
779
|
+
function _signInternal(M, secretKey, rnd) {
|
|
780
|
+
if (secretKey.length !== SK_LEN) {
|
|
781
|
+
console.warn('[crypto] INVALID: ml_dsa: wrong secretKey length');
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
const { tr } = _decodeSK(secretKey);
|
|
785
|
+
const muIn = new Uint8Array(tr.length + M.length);
|
|
786
|
+
muIn.set(tr, 0); muIn.set(M, tr.length);
|
|
787
|
+
const mu = _shake256(muIn, CRH_BYTES);
|
|
788
|
+
return _signFromMu(mu, secretKey, rnd);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Pure ML-DSA sign (FIPS 204 §5.4 PureML-DSA + §6.2 internal).
|
|
793
|
+
* Wraps the message with the §5.4 prefix `0x00 || |ctx| || ctx ||
|
|
794
|
+
* msg` then calls the internal signing path.
|
|
795
|
+
*/
|
|
796
|
+
function sign(msg, secretKey, ctx, rnd) {
|
|
797
|
+
const M = _wrapMessage(msg, ctx);
|
|
798
|
+
if (M === false) return false;
|
|
799
|
+
return _signInternal(M, secretKey, rnd);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* HashML-DSA sign (FIPS 204 §5.4 Algorithm 4). Caller passes the
|
|
804
|
+
* **raw** message ; we compute PH(message) using the supplied hash
|
|
805
|
+
* module then build the FIPS 204 OID-prefixed wrapper and sign.
|
|
806
|
+
*
|
|
807
|
+
* @param {Uint8Array} msg
|
|
808
|
+
* @param {Uint8Array} secretKey
|
|
809
|
+
* @param {string} hashAlg One of the keys of `_HASH_OIDS`.
|
|
810
|
+
* @param {{hash:Function,shake?:Function}|null} hashMod hash module
|
|
811
|
+
* (sha256, sha384, ...). For SHAKE-128/-256 the module must
|
|
812
|
+
* expose `(data, outBits) => bitArray` (cf. sha3.js).
|
|
813
|
+
* @param {Uint8Array} [ctx]
|
|
814
|
+
* @param {Uint8Array} [rnd]
|
|
815
|
+
*/
|
|
816
|
+
function signPh(msg, secretKey, hashAlg, hashMod, ctx, rnd) {
|
|
817
|
+
const ph = _computePh(msg, hashAlg, hashMod);
|
|
818
|
+
if (ph === false) return false;
|
|
819
|
+
const M = _wrapMessageHash(ph, ctx, hashAlg);
|
|
820
|
+
if (M === false) return false;
|
|
821
|
+
return _signInternal(M, secretKey, rnd);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// Compute PH(msg) per FIPS 204 §5.4.1 - hash modules from this
|
|
825
|
+
// codebase consume either a string or a bitArray (NOT Uint8Array)
|
|
826
|
+
// and return a bitArray. We convert msg → bitArray, hash, then
|
|
827
|
+
// bitArray → bytes. For SHAKE outputs : truncate to 256 bits
|
|
828
|
+
// (SHAKE-128) or 512 bits (SHAKE-256) per FIPS 204 standard digest
|
|
829
|
+
// sizes (cf. _HASH_OIDS).
|
|
830
|
+
function _computePh(msg, hashAlg, hashMod) {
|
|
831
|
+
if (!hashMod) {
|
|
832
|
+
console.warn('[crypto] INVALID: ml_dsa: signPh requires a hashMod');
|
|
833
|
+
return false;
|
|
834
|
+
}
|
|
835
|
+
const msgBa = (msg instanceof Uint8Array) ? bitArray.ui8_to_ba(msg) : msg;
|
|
836
|
+
if (hashAlg === 'SHAKE-128' || hashAlg === 'SHAKE-256') {
|
|
837
|
+
if (typeof hashMod !== 'function') {
|
|
838
|
+
console.warn('[crypto] INVALID: ml_dsa: SHAKE hashMod must be a callable (data, outBits)');
|
|
839
|
+
return false;
|
|
840
|
+
}
|
|
841
|
+
const outBits = hashAlg === 'SHAKE-128' ? 256 : 512;
|
|
842
|
+
const ba = hashMod(msgBa, outBits);
|
|
843
|
+
if (ba === false) return false;
|
|
844
|
+
return _baToBytes(ba);
|
|
845
|
+
}
|
|
846
|
+
if (typeof hashMod.hash !== 'function') {
|
|
847
|
+
console.warn('[crypto] INVALID: ml_dsa: hashMod must expose .hash(data)');
|
|
848
|
+
return false;
|
|
849
|
+
}
|
|
850
|
+
return _baToBytes(hashMod.hash(msgBa));
|
|
851
|
+
}
|
|
852
|
+
// Best-effort bitArray → Uint8Array (lazy require to avoid cyclic
|
|
853
|
+
// factory dependency : caller injects bitArray as the second
|
|
854
|
+
// factory dep, already in scope).
|
|
855
|
+
function _baToBytes(ba) {
|
|
856
|
+
if (ba instanceof Uint8Array) return ba;
|
|
857
|
+
return bitArray.ba_to_ui8(ba);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
// ── verify (FIPS 204 Algorithm 3 / §6.3) ────────────────
|
|
861
|
+
|
|
862
|
+
// Verify against a pre-computed mu (externalMu / internal path).
|
|
863
|
+
function _verifyFromMu(sig, mu, publicKey) {
|
|
864
|
+
if (sig.length !== SIG_LEN) return false;
|
|
865
|
+
if (publicKey.length !== PK_LEN) return false;
|
|
866
|
+
if (!(mu instanceof Uint8Array) || mu.length !== CRH_BYTES) return false;
|
|
867
|
+
|
|
868
|
+
const { rho, t1 } = _decodePK(publicKey);
|
|
869
|
+
const dec = _decodeSig(sig);
|
|
870
|
+
if (dec.h === false) return false;
|
|
871
|
+
const { cTilde, z, h } = dec;
|
|
872
|
+
for (let i = 0; i < L; i++) if (_polyChknorm(z[i], GAMMA1 - BETA)) return false;
|
|
873
|
+
|
|
874
|
+
const c = _sampleInBall(cTilde, TAU);
|
|
875
|
+
if (c === false) return false;
|
|
876
|
+
const cHat = new Int32Array(c); _ntt(cHat);
|
|
877
|
+
|
|
878
|
+
// wApprox = NTT^-1(A * NTT(z) - cHat * NTT(t1 << D))
|
|
879
|
+
const zHat = new Array(L);
|
|
880
|
+
for (let i = 0; i < L; i++) { zHat[i] = new Int32Array(z[i]); _ntt(zHat[i]); }
|
|
881
|
+
|
|
882
|
+
const wTick1 = new Array(K);
|
|
883
|
+
const tmp = new Int32Array(N);
|
|
884
|
+
for (let i = 0; i < K; i++) {
|
|
885
|
+
const t1Shift = new Int32Array(N);
|
|
886
|
+
for (let k = 0; k < N; k++) t1Shift[k] = _mod(t1[i][k] << D);
|
|
887
|
+
_ntt(t1Shift);
|
|
888
|
+
const ct12d = new Int32Array(N);
|
|
889
|
+
_multiplyNTTs(ct12d, cHat, t1Shift);
|
|
890
|
+
const Az = new Int32Array(N);
|
|
891
|
+
for (let j = 0; j < L; j++) {
|
|
892
|
+
const aij = _rejNTTPoly(rho, j, i);
|
|
893
|
+
_multiplyNTTs(tmp, aij, zHat[j]);
|
|
894
|
+
_polyAdd(Az, tmp);
|
|
895
|
+
}
|
|
896
|
+
_polySub(Az, ct12d);
|
|
897
|
+
_nttInv(Az);
|
|
898
|
+
const w = new Int32Array(N);
|
|
899
|
+
for (let k = 0; k < N; k++) w[k] = _useHint(h[i][k], Az[k], GAMMA2);
|
|
900
|
+
wTick1[i] = w;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
let hCount = 0;
|
|
904
|
+
for (let i = 0; i < K; i++)
|
|
905
|
+
for (let k = 0; k < N; k++) hCount += h[i][k];
|
|
906
|
+
if (hCount > OMEGA) return false;
|
|
907
|
+
|
|
908
|
+
const w1Bytes = new Uint8Array(K * W1_BYTES);
|
|
909
|
+
for (let i = 0; i < K; i++) w1Bytes.set(_packW1(wTick1[i], GAMMA2), i * W1_BYTES);
|
|
910
|
+
const cIn = new Uint8Array(CRH_BYTES + w1Bytes.length);
|
|
911
|
+
cIn.set(mu, 0); cIn.set(w1Bytes, CRH_BYTES);
|
|
912
|
+
const cTilde2 = _shake256(cIn, C_TILDE_BYTES);
|
|
913
|
+
|
|
914
|
+
if (cTilde.length !== cTilde2.length) return false;
|
|
915
|
+
let diff = 0;
|
|
916
|
+
for (let i = 0; i < cTilde.length; i++) diff |= cTilde[i] ^ cTilde2[i];
|
|
917
|
+
return diff === 0;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
// Compute mu from (publicKey-derived tr) || M, then verify.
|
|
921
|
+
function _verifyInternal(sig, M, publicKey) {
|
|
922
|
+
if (publicKey.length !== PK_LEN) return false;
|
|
923
|
+
const tr = _shake256(publicKey, TR_BYTES);
|
|
924
|
+
const muIn = new Uint8Array(tr.length + M.length);
|
|
925
|
+
muIn.set(tr, 0); muIn.set(M, tr.length);
|
|
926
|
+
const mu = _shake256(muIn, CRH_BYTES);
|
|
927
|
+
return _verifyFromMu(sig, mu, publicKey);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/** Pure ML-DSA verify (FIPS 204 §5.4 PureML-DSA + §6.3). */
|
|
931
|
+
function verify(sig, msg, publicKey, ctx) {
|
|
932
|
+
const M = _wrapMessage(msg, ctx);
|
|
933
|
+
if (M === false) return false;
|
|
934
|
+
return _verifyInternal(sig, M, publicKey);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
/** HashML-DSA verify (FIPS 204 §5.4 Algorithm 5). */
|
|
938
|
+
function verifyPh(sig, msg, publicKey, hashAlg, hashMod, ctx) {
|
|
939
|
+
const ph = _computePh(msg, hashAlg, hashMod);
|
|
940
|
+
if (ph === false) return false;
|
|
941
|
+
const M = _wrapMessageHash(ph, ctx, hashAlg);
|
|
942
|
+
if (M === false) return false;
|
|
943
|
+
return _verifyInternal(sig, M, publicKey);
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
return {
|
|
947
|
+
lengths: Object.freeze({
|
|
948
|
+
publicKey: PK_LEN, secretKey: SK_LEN, signature: SIG_LEN, seed: 32
|
|
949
|
+
}),
|
|
950
|
+
keygen, sign, verify,
|
|
951
|
+
// Iteration E3 of the FIPS 140-3 upgrade plan - HashML-DSA
|
|
952
|
+
// (FIPS 204 §5.4 Algorithms 4 + 5).
|
|
953
|
+
signPh, verifyPh,
|
|
954
|
+
// Internal escape hatches (test-only). signInternal and
|
|
955
|
+
// verifyInternal expose the §6.2/§6.3 raw paths (no §5.4
|
|
956
|
+
// wrapping). signWithMu / verifyWithMu accept a pre-computed
|
|
957
|
+
// mu for the externalMu API mode.
|
|
958
|
+
_internal: {
|
|
959
|
+
signInternal: _signInternal,
|
|
960
|
+
verifyInternal: _verifyInternal,
|
|
961
|
+
signWithMu: _signFromMu,
|
|
962
|
+
verifyWithMu: _verifyFromMu,
|
|
963
|
+
wrapMessage: _wrapMessage,
|
|
964
|
+
wrapMessageHash: _wrapMessageHash,
|
|
965
|
+
computePh: _computePh
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
const PARAMS = {
|
|
971
|
+
44: { K: 4, L: 4, GAMMA1: 1 << 17, GAMMA2: GAMMA2_1, TAU: 39, ETA: 2, OMEGA: 80, C_TILDE_BYTES: 32 },
|
|
972
|
+
65: { K: 6, L: 5, GAMMA1: 1 << 19, GAMMA2: GAMMA2_2, TAU: 49, ETA: 4, OMEGA: 55, C_TILDE_BYTES: 48 },
|
|
973
|
+
87: { K: 8, L: 7, GAMMA1: 1 << 19, GAMMA2: GAMMA2_2, TAU: 60, ETA: 2, OMEGA: 75, C_TILDE_BYTES: 64 }
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
return {
|
|
977
|
+
ml_dsa44: _make(PARAMS[44]),
|
|
978
|
+
ml_dsa65: _make(PARAMS[65]),
|
|
979
|
+
ml_dsa87: _make(PARAMS[87]),
|
|
980
|
+
// exposed for testing
|
|
981
|
+
_ntt, _nttInv
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
};
|