@awacloud/fw 0.1.0 → 1.0.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 +125 -0
- package/NOTICE +8 -0
- package/README.md +163 -31
- package/dist/build/fw.core.pure.meta.json +6 -6
- package/dist/build/fw.core.pure.min.js +15 -12
- package/dist/build/fw.full.pure.meta.json +13 -7
- package/dist/build/fw.full.pure.min.js +45 -42
- package/dist/build/fw.minimal.pure.meta.json +6 -6
- package/dist/build/fw.minimal.pure.min.js +16 -13
- package/dist/build/fw.pack.compress-heavy.pure.meta.json +6 -6
- package/dist/build/fw.pack.compress-heavy.pure.min.js +3 -3
- package/dist/build/fw.pack.crypto-advanced.pure.meta.json +6 -6
- package/dist/build/fw.pack.crypto-advanced.pure.min.js +1 -1
- package/dist/build/fw.pack.crypto-basic.pure.meta.json +6 -6
- package/dist/build/fw.pack.crypto-basic.pure.min.js +1 -1
- package/dist/build/fw.pack.crypto-identity.pure.meta.json +7 -6
- package/dist/build/fw.pack.crypto-identity.pure.min.js +4 -4
- package/dist/build/fw.pwa.pure.meta.json +7 -6
- package/dist/build/fw.pwa.pure.min.js +38 -35
- package/dist/build/fw.site-interactive.pure.meta.json +6 -6
- package/dist/build/fw.site-interactive.pure.min.js +37 -34
- package/dist/build/fw.site.pure.meta.json +6 -6
- package/dist/build/fw.site.pure.min.js +24 -21
- package/dist/build/fw.spa.pure.meta.json +8 -7
- package/dist/build/fw.spa.pure.min.js +41 -38
- package/dist/build/sanity-base-classic.min.js +1 -1
- package/dist/build/sanity.min.js +1 -1
- package/dist/types/core/internal.d.ts +29 -0
- package/dist/types/core/internal.d.ts.map +1 -0
- package/dist/types/core/logger.d.ts +23 -4
- package/dist/types/core/logger.d.ts.map +1 -1
- package/dist/types/core/modules.d.ts +374 -61
- package/dist/types/core/modules.d.ts.map +1 -1
- package/dist/types/core/runtime.d.ts +10 -6
- package/dist/types/core/runtime.d.ts.map +1 -1
- package/dist/types/core/worker-helper.d.ts +35 -0
- package/dist/types/core/worker-helper.d.ts.map +1 -1
- package/dist/types/crypto/cipher/aes.d.ts +1 -7
- package/dist/types/crypto/cipher/aes.d.ts.map +1 -1
- package/dist/types/crypto/cipher/chacha20.d.ts +0 -10
- package/dist/types/crypto/cipher/chacha20.d.ts.map +1 -1
- package/dist/types/crypto/hash/argon2.d.ts +0 -15
- package/dist/types/crypto/hash/argon2.d.ts.map +1 -1
- package/dist/types/crypto/hash/blake2b.d.ts.map +1 -1
- package/dist/types/crypto/hash/hmac.d.ts.map +1 -1
- package/dist/types/crypto/hash/pbkdf2.d.ts.map +1 -1
- package/dist/types/crypto/hash/poly1305.d.ts.map +1 -1
- package/dist/types/crypto/hash/sha224.d.ts +1 -1
- package/dist/types/crypto/hash/sha256.d.ts +4 -13
- package/dist/types/crypto/hash/sha256.d.ts.map +1 -1
- package/dist/types/crypto/hash/sha3.d.ts.map +1 -1
- package/dist/types/crypto/hash/sha384.d.ts +1 -1
- package/dist/types/crypto/hash/sha512.d.ts +4 -13
- package/dist/types/crypto/hash/sha512.d.ts.map +1 -1
- package/dist/types/crypto/mode/cmac.d.ts +0 -6
- package/dist/types/crypto/mode/cmac.d.ts.map +1 -1
- package/dist/types/crypto/mode/ctr.d.ts +0 -6
- package/dist/types/crypto/mode/ctr.d.ts.map +1 -1
- package/dist/types/crypto/mode/gcm.d.ts +0 -9
- package/dist/types/crypto/mode/gcm.d.ts.map +1 -1
- package/dist/types/crypto/pkc/ecc.d.ts +0 -1
- package/dist/types/crypto/pkc/ecc.d.ts.map +1 -1
- package/dist/types/crypto/pkc/ed25519.d.ts +4 -25
- package/dist/types/crypto/pkc/ed25519.d.ts.map +1 -1
- package/dist/types/crypto/pkc/hybridSign.d.ts +25 -5
- package/dist/types/crypto/pkc/hybridSign.d.ts.map +1 -1
- package/dist/types/crypto/pkc/ml_dsa.d.ts +6 -26
- package/dist/types/crypto/pkc/ml_dsa.d.ts.map +1 -1
- package/dist/types/crypto/pkc/ml_kem.d.ts +0 -43
- package/dist/types/crypto/pkc/ml_kem.d.ts.map +1 -1
- package/dist/types/crypto/pkc/rsa.d.ts +0 -24
- package/dist/types/crypto/pkc/rsa.d.ts.map +1 -1
- package/dist/types/crypto/pkc/slh_dsa.d.ts +6 -16
- package/dist/types/crypto/pkc/slh_dsa.d.ts.map +1 -1
- package/dist/types/crypto/pkc/x25519.d.ts +0 -6
- package/dist/types/crypto/pkc/x25519.d.ts.map +1 -1
- package/dist/types/crypto/utils/bitArray.d.ts +0 -8
- package/dist/types/crypto/utils/bitArray.d.ts.map +1 -1
- package/dist/types/crypto/utils/jws.d.ts +6 -14
- package/dist/types/crypto/utils/jws.d.ts.map +1 -1
- package/dist/types/crypto/utils/keyformat.d.ts +52 -0
- package/dist/types/crypto/utils/keyformat.d.ts.map +1 -1
- package/dist/types/crypto/utils/random.d.ts +1 -10
- package/dist/types/crypto/utils/random.d.ts.map +1 -1
- package/dist/types/crypto/utils/rsaKeygen.d.ts +0 -10
- package/dist/types/crypto/utils/rsaKeygen.d.ts.map +1 -1
- package/dist/types/crypto/utils/uuid.d.ts.map +1 -1
- package/dist/types/crypto/utils/x509.d.ts +397 -0
- package/dist/types/crypto/utils/x509.d.ts.map +1 -0
- package/dist/types/crypto/wasm/argon2.d.ts +2 -1
- package/dist/types/crypto/wasm/argon2.d.ts.map +1 -1
- package/dist/types/crypto/wasm/pbkdf2.d.ts +2 -2
- package/dist/types/crypto/wasm/pbkdf2.d.ts.map +1 -1
- package/dist/types/crypto/wasm/rsa.d.ts.map +1 -1
- package/dist/types/crypto/wasm/runtime.d.ts +13 -0
- package/dist/types/crypto/wasm/runtime.d.ts.map +1 -1
- package/dist/types/crypto/webcrypto/aes.d.ts.map +1 -1
- package/dist/types/crypto/webcrypto/aeskw.d.ts.map +1 -1
- package/dist/types/crypto/webcrypto/digest.d.ts +0 -4
- package/dist/types/crypto/webcrypto/digest.d.ts.map +1 -1
- package/dist/types/crypto/webcrypto/rsa.d.ts.map +1 -1
- package/dist/types/dom/fs/fileIntake.d.ts +59 -0
- package/dist/types/dom/fs/fileIntake.d.ts.map +1 -0
- package/dist/types/dom/fs/fsAccess.d.ts.map +1 -1
- package/dist/types/dom/query/dnd.d.ts.map +1 -1
- package/dist/types/dom/query/sound.d.ts +89 -0
- package/dist/types/dom/query/sound.d.ts.map +1 -0
- package/dist/types/dom/rendering/chart.d.ts.map +1 -1
- package/dist/types/dom/rendering/component.d.ts +9 -3
- package/dist/types/dom/rendering/component.d.ts.map +1 -1
- package/dist/types/dom/rendering/parser.d.ts +39 -0
- package/dist/types/dom/rendering/parser.d.ts.map +1 -1
- package/dist/types/dom/rendering/render.d.ts.map +1 -1
- package/dist/types/dom/rendering/sanitize.d.ts +4 -0
- package/dist/types/dom/rendering/sanitize.d.ts.map +1 -1
- package/dist/types/dom/rendering/secPolicy.d.ts.map +1 -1
- package/dist/types/dom/rendering/styleSheet.d.ts +74 -0
- package/dist/types/dom/rendering/styleSheet.d.ts.map +1 -0
- package/dist/types/dom/rendering/template.d.ts +9 -3
- package/dist/types/dom/rendering/template.d.ts.map +1 -1
- package/dist/types/dom/rendering/themeTokens.d.ts +9 -3
- package/dist/types/dom/rendering/themeTokens.d.ts.map +1 -1
- package/dist/types/dom/rendering/uiSession-core.d.ts +9 -3
- package/dist/types/dom/rendering/uiSession-core.d.ts.map +1 -1
- package/dist/types/dom/rendering/uiSession-list.d.ts +9 -3
- package/dist/types/dom/rendering/uiSession-list.d.ts.map +1 -1
- package/dist/types/dom/rendering/uiSession.d.ts +18 -6
- package/dist/types/dom/rendering/uiSession.d.ts.map +1 -1
- package/dist/types/dom/sw/installPrompt.d.ts +89 -0
- package/dist/types/dom/sw/installPrompt.d.ts.map +1 -0
- package/dist/types/dom/sw/precache.d.ts +149 -0
- package/dist/types/dom/sw/precache.d.ts.map +1 -0
- package/dist/types/dom/sw/swUpdate.d.ts +129 -0
- package/dist/types/dom/sw/swUpdate.d.ts.map +1 -0
- package/dist/types/dom/utils/clipboard.d.ts +8 -0
- package/dist/types/dom/utils/clipboard.d.ts.map +1 -1
- package/dist/types/dom/utils/keybindings.d.ts.map +1 -1
- package/dist/types/dom/utils/route.d.ts.map +1 -1
- package/dist/types/dom/utils/ua.d.ts +2 -2
- package/dist/types/dom/utils/ua.d.ts.map +1 -1
- package/dist/types/io/calc/crc32.d.ts.map +1 -1
- package/dist/types/io/codec/b64.d.ts +24 -0
- package/dist/types/io/codec/b64.d.ts.map +1 -1
- package/dist/types/io/codec/cbor.d.ts +1 -0
- package/dist/types/io/codec/cbor.d.ts.map +1 -1
- package/dist/types/io/codec/hex.d.ts.map +1 -1
- package/dist/types/io/codec/msgpack.d.ts +1 -0
- package/dist/types/io/codec/msgpack.d.ts.map +1 -1
- package/dist/types/io/codec/url.d.ts +3 -1
- package/dist/types/io/codec/url.d.ts.map +1 -1
- package/dist/types/io/codec/utf8.d.ts.map +1 -1
- package/dist/types/io/compress/bitstream.d.ts +1 -1
- package/dist/types/io/compress/brotli.d.ts +0 -1
- package/dist/types/io/compress/brotli.d.ts.map +1 -1
- package/dist/types/io/compress/brotli_shared.d.ts +0 -4
- package/dist/types/io/compress/brotli_shared.d.ts.map +1 -1
- package/dist/types/io/compress/deflate.d.ts +14 -1
- package/dist/types/io/compress/deflate.d.ts.map +1 -1
- package/dist/types/io/compress/gzip.d.ts +4 -0
- package/dist/types/io/compress/gzip.d.ts.map +1 -1
- package/dist/types/io/compress/huffman.d.ts +7 -0
- package/dist/types/io/compress/huffman.d.ts.map +1 -1
- package/dist/types/io/compress/lz4.d.ts +4 -2
- package/dist/types/io/compress/lz4.d.ts.map +1 -1
- package/dist/types/io/compress/lz77.d.ts +17 -0
- package/dist/types/io/compress/lz77.d.ts.map +1 -1
- package/dist/types/io/compress/lzw.d.ts +2 -0
- package/dist/types/io/compress/lzw.d.ts.map +1 -1
- package/dist/types/io/compress/zip.d.ts.map +1 -1
- package/dist/types/io/compress/zlib.d.ts +9 -2
- package/dist/types/io/compress/zlib.d.ts.map +1 -1
- package/dist/types/io/math/linalg.d.ts.map +1 -1
- package/dist/types/process/rpc.d.ts.map +1 -1
- package/dist/types/process/workerPool.d.ts.map +1 -1
- package/dist/types/sanity/base.d.ts +12 -2
- package/dist/types/sanity/base.d.ts.map +1 -1
- package/dist/types/sanity/lockdown.d.ts +6 -5
- package/dist/types/sanity/lockdown.d.ts.map +1 -1
- package/dist/types/sanity/wasm-gate.d.ts +1 -1
- package/docs/README.md +17 -10
- package/docs/api/README.md +5 -5
- package/docs/api/core/logger.md +2 -1
- package/docs/api/core/modules.md +3 -3
- package/docs/api/core/runtime.md +9 -9
- package/docs/api/core/worker-helper.md +12 -2
- package/docs/api/crypto/README.md +1 -1
- package/docs/api/crypto/cipher/README.md +2 -2
- package/docs/api/crypto/cipher/aes.md +5 -10
- package/docs/api/crypto/cipher/chacha20.md +3 -8
- package/docs/api/crypto/hash/README.md +5 -5
- package/docs/api/crypto/hash/adf.md +21 -11
- package/docs/api/crypto/hash/argon2.md +3 -12
- package/docs/api/crypto/hash/blake2b.md +12 -14
- package/docs/api/crypto/hash/pbkdf2.md +1 -1
- package/docs/api/crypto/hash/sha224.md +2 -2
- package/docs/api/crypto/hash/sha256.md +4 -4
- package/docs/api/crypto/hash/sha3.md +2 -2
- package/docs/api/crypto/hash/sha384.md +1 -1
- package/docs/api/crypto/hash/sha512.md +5 -5
- package/docs/api/crypto/hash/sha512_224.md +1 -1
- package/docs/api/crypto/hash/sha512_256.md +1 -1
- package/docs/api/crypto/mode/README.md +3 -3
- package/docs/api/crypto/mode/cbc.md +2 -2
- package/docs/api/crypto/mode/chacha20poly1305.md +1 -1
- package/docs/api/crypto/mode/cmac.md +4 -4
- package/docs/api/crypto/mode/ctr.md +2 -3
- package/docs/api/crypto/mode/gcm.md +5 -5
- package/docs/api/crypto/mode/kw.md +4 -4
- package/docs/api/crypto/pkc/README.md +8 -8
- package/docs/api/crypto/pkc/ecc.md +19 -17
- package/docs/api/crypto/pkc/ed25519.md +10 -15
- package/docs/api/crypto/pkc/hybridKem.md +8 -2
- package/docs/api/crypto/pkc/hybridSign.md +34 -7
- package/docs/api/crypto/pkc/ml_dsa.md +20 -19
- package/docs/api/crypto/pkc/ml_kem.md +3 -3
- package/docs/api/crypto/pkc/rsa.md +7 -9
- package/docs/api/crypto/pkc/slh_dsa.md +12 -12
- package/docs/api/crypto/pkc/x25519.md +5 -4
- package/docs/api/crypto/utils/README.md +7 -7
- package/docs/api/crypto/utils/aes_modes.md +2 -5
- package/docs/api/crypto/utils/asn1.md +25 -16
- package/docs/api/crypto/utils/jws.md +6 -4
- package/docs/api/crypto/utils/keyformat.md +24 -15
- package/docs/api/crypto/utils/pad.md +1 -1
- package/docs/api/crypto/utils/pem.md +3 -3
- package/docs/api/crypto/utils/random.md +3 -4
- package/docs/api/crypto/utils/rsaKeygen.md +2 -2
- package/docs/api/crypto/utils/totp.md +2 -2
- package/docs/api/crypto/utils/uuid.md +5 -5
- package/docs/api/crypto/utils/x509.md +124 -0
- package/docs/api/crypto/wasm/aes.md +1 -1
- package/docs/api/crypto/wasm/argon2.md +6 -4
- package/docs/api/crypto/wasm/ml_kem.md +1 -0
- package/docs/api/crypto/wasm/pbkdf2.md +8 -8
- package/docs/api/crypto/wasm/rsa.md +1 -1
- package/docs/api/crypto/wasm/runtime.md +27 -10
- package/docs/api/crypto/webcrypto/aes.md +1 -1
- package/docs/api/crypto/webcrypto/aeskw.md +2 -2
- package/docs/api/crypto/webcrypto/digest.md +3 -5
- package/docs/api/crypto/webcrypto/ecc.md +1 -1
- package/docs/api/crypto/webcrypto/ed25519.md +1 -1
- package/docs/api/crypto/webcrypto/rsa.md +3 -2
- package/docs/api/crypto/webcrypto/x25519.md +1 -1
- package/docs/api/dom/README.md +6 -1
- package/docs/api/dom/fs/README.md +1 -0
- package/docs/api/dom/fs/fileIntake.md +120 -0
- package/docs/api/dom/fs/fsAccess.md +1 -0
- package/docs/api/dom/fs/indexedDB.md +1 -1
- package/docs/api/dom/fs/storage.md +1 -1
- package/docs/api/dom/query/README.md +2 -1
- package/docs/api/dom/query/dnd.md +4 -1
- package/docs/api/dom/query/dom.md +5 -0
- package/docs/api/dom/query/sound.md +103 -0
- package/docs/api/dom/rendering/README.md +4 -3
- package/docs/api/dom/rendering/chart.md +5 -4
- package/docs/api/dom/rendering/component.md +25 -3
- package/docs/api/dom/rendering/parser.md +5 -2
- package/docs/api/dom/rendering/reactiveBind.md +1 -1
- package/docs/api/dom/rendering/render.md +2 -2
- package/docs/api/dom/rendering/sanitize.md +10 -2
- package/docs/api/dom/rendering/secPolicy.md +4 -4
- package/docs/api/dom/rendering/styleSheet.md +85 -0
- package/docs/api/dom/rendering/template.md +20 -5
- package/docs/api/dom/rendering/themeTokens.md +6 -3
- package/docs/api/dom/rendering/uiSession.md +18 -5
- package/docs/api/dom/rendering/virtualScroll.md +2 -2
- package/docs/api/dom/sensors/geolocation.md +1 -1
- package/docs/api/dom/sw/README.md +7 -1
- package/docs/api/dom/sw/cache.md +2 -1
- package/docs/api/dom/sw/installPrompt.md +111 -0
- package/docs/api/dom/sw/precache.md +124 -0
- package/docs/api/dom/sw/serviceWorker.md +4 -2
- package/docs/api/dom/sw/swUpdate.md +112 -0
- package/docs/api/dom/utils/clipboard.md +56 -5
- package/docs/api/dom/utils/entropyCollector.md +1 -1
- package/docs/api/dom/utils/keybindings.md +17 -2
- package/docs/api/dom/utils/leaderElection.md +2 -2
- package/docs/api/dom/utils/route.md +1 -0
- package/docs/api/dom/utils/ua.md +15 -10
- package/docs/api/io/calc/crc32.md +4 -1
- package/docs/api/io/codec/README.md +2 -2
- package/docs/api/io/codec/b64.md +31 -2
- package/docs/api/io/codec/buffer.md +1 -1
- package/docs/api/io/codec/cbor.md +6 -4
- package/docs/api/io/codec/csv.md +178 -178
- package/docs/api/io/codec/hex.md +10 -2
- package/docs/api/io/codec/msgpack.md +4 -3
- package/docs/api/io/codec/url.md +4 -3
- package/docs/api/io/codec/utf8.md +3 -3
- package/docs/api/io/compress/bitstream.md +6 -3
- package/docs/api/io/compress/brotli.md +36 -4
- package/docs/api/io/compress/brotli_shared.md +1 -1
- package/docs/api/io/compress/deflate.md +42 -34
- package/docs/api/io/compress/gzip.md +26 -6
- package/docs/api/io/compress/huffman.md +2 -1
- package/docs/api/io/compress/lz4.md +5 -3
- package/docs/api/io/compress/lz77.md +26 -3
- package/docs/api/io/compress/lzw.md +13 -8
- package/docs/api/io/compress/zip.md +36 -10
- package/docs/api/io/compress/zlib.md +21 -5
- package/docs/api/io/math/linalg.md +1 -1
- package/docs/api/io/utils/valid.md +1 -1
- package/docs/api/process/rpc.md +3 -2
- package/docs/api/process/workerPool.md +1 -1
- package/docs/api/sanity/base.md +9 -5
- package/docs/api/sanity/lockdown.md +7 -6
- package/docs/api/surface.json +12311 -0
- package/docs/api/typed.md +5 -3
- package/docs/dev/README.md +2 -0
- package/docs/dev/bench.md +76 -0
- package/docs/dev/crypto-references.md +54 -0
- package/docs/dev/provenance.md +30 -7
- package/docs/dev/publishing.md +7 -7
- package/docs/dev/runtime.md +1 -1
- package/docs/dev/testing.md +13 -0
- package/docs/evidence/l4-evidence.md +86 -0
- package/docs/evidence/pqc-hybrid-evidence.md +7 -6
- package/docs/guide/README.md +1 -0
- package/docs/guide/_QUICK_REF.md +5 -5
- package/docs/guide/doc-format.md +4 -3
- package/docs/guide/integrations-hmr.md +1 -1
- package/docs/guide/module-creation-workflow.md +8 -8
- package/docs/guide/rendering-pipeline.md +11 -4
- package/docs/guide/security.md +7 -5
- package/docs/guide/stability.md +123 -0
- package/docs/guide/tutorial-todo.md +20 -8
- package/docs/guide/typescript.md +9 -0
- package/docs/guide/worker-confinement.md +30 -17
- package/docs/notes/lz77-deflate-factorization.md +3 -3
- package/docs/tools/README.md +1 -1
- package/docs/tools/bundler.md +3 -3
- package/docs/tools/codegen.md +1 -1
- package/docs/tools/standalone.md +0 -1
- package/fw.config.json +2 -2
- package/integrations/_shared/catalog.generated.json +7 -1
- package/integrations/_shared/core.js +1 -1
- package/integrations/astro/index.js +1 -1
- package/integrations/eslint/README.md +7 -1
- package/integrations/nextjs/index.js +1 -1
- package/integrations/nodejs/README.md +3 -3
- package/integrations/turbopack/index.js +2 -2
- package/integrations/typedoc/categorize.js +1 -1
- package/integrations/typedoc/typedoc.json +2 -1
- package/integrations/vite/index.js +2 -2
- package/integrations/vite/vite-env.d.ts +7 -4
- package/integrations/webpack/index.js +3 -3
- package/package.json +76 -10
- package/src/core/internal.js +31 -0
- package/src/core/logger.js +95 -23
- package/src/core/modules.js +17 -8
- package/src/core/readyState.js +1 -1
- package/src/core/runtime.js +74 -27
- package/src/core/worker-helper.js +83 -4
- package/src/crypto/NIST_CONFORMANCE.md +47 -34
- package/src/crypto/cipher/aes.acvp.md +7 -8
- package/src/crypto/cipher/aes.js +280 -229
- package/src/crypto/cipher/chacha20.acvp.md +6 -7
- package/src/crypto/cipher/chacha20.js +91 -61
- package/src/crypto/hash/adf.js +1 -1
- package/src/crypto/hash/argon2.acvp.md +11 -15
- package/src/crypto/hash/argon2.js +9 -24
- package/src/crypto/hash/blake2b.js +157 -125
- package/src/crypto/hash/hkdf.acvp.md +15 -15
- package/src/crypto/hash/hkdf.js +1 -1
- package/src/crypto/hash/hmac.acvp.md +10 -12
- package/src/crypto/hash/hmac.js +5 -1
- package/src/crypto/hash/pbkdf2.acvp.md +13 -13
- package/src/crypto/hash/pbkdf2.js +36 -8
- package/src/crypto/hash/poly1305.acvp.md +10 -6
- package/src/crypto/hash/poly1305.js +171 -50
- package/src/crypto/hash/sha224.acvp.md +3 -3
- package/src/crypto/hash/sha224.js +4 -4
- package/src/crypto/hash/sha256.acvp.md +2 -2
- package/src/crypto/hash/sha256.js +514 -50
- package/src/crypto/hash/sha3.acvp.md +9 -9
- package/src/crypto/hash/sha3.js +127 -71
- package/src/crypto/hash/sha384.acvp.md +3 -3
- package/src/crypto/hash/sha384.js +4 -4
- package/src/crypto/hash/sha512.acvp.md +7 -8
- package/src/crypto/hash/sha512.js +107 -108
- package/src/crypto/hash/sha512_224.acvp.md +6 -6
- package/src/crypto/hash/sha512_224.js +2 -2
- package/src/crypto/hash/sha512_256.acvp.md +6 -6
- package/src/crypto/hash/sha512_256.js +2 -2
- package/src/crypto/mode/cbc.acvp.md +2 -2
- package/src/crypto/mode/cbc.js +1 -1
- package/src/crypto/mode/chacha20poly1305.acvp.md +6 -6
- package/src/crypto/mode/chacha20poly1305.js +3 -3
- package/src/crypto/mode/cmac.acvp.md +5 -5
- package/src/crypto/mode/cmac.js +8 -8
- package/src/crypto/mode/ctr.acvp.md +2 -2
- package/src/crypto/mode/ctr.js +1 -3
- package/src/crypto/mode/gcm.acvp.md +6 -6
- package/src/crypto/mode/gcm.js +7 -7
- package/src/crypto/mode/kw.acvp.md +4 -4
- package/src/crypto/mode/kw.js +5 -5
- package/src/crypto/pkc/ecc.acvp.md +13 -13
- package/src/crypto/pkc/ecc.js +9 -11
- package/src/crypto/pkc/ed25519.acvp.md +30 -34
- package/src/crypto/pkc/ed25519.js +453 -94
- package/src/crypto/pkc/hybrid-kat.provenance.md +4 -4
- package/src/crypto/pkc/hybridSign.js +103 -24
- package/src/crypto/pkc/ml_dsa.acvp.md +18 -18
- package/src/crypto/pkc/ml_dsa.js +29 -32
- package/src/crypto/pkc/ml_kem.acvp.md +7 -7
- package/src/crypto/pkc/ml_kem.js +15 -21
- package/src/crypto/pkc/rsa.acvp.md +11 -15
- package/src/crypto/pkc/rsa.js +7 -44
- package/src/crypto/pkc/slh_dsa.acvp.md +16 -16
- package/src/crypto/pkc/slh_dsa.js +16 -18
- package/src/crypto/pkc/x25519.acvp.md +13 -10
- package/src/crypto/pkc/x25519.js +273 -29
- package/src/crypto/utils/aes_modes.acvp.md +1 -2
- package/src/crypto/utils/aes_modes.js +2 -2
- package/src/crypto/utils/asn1-oid.js +1 -1
- package/src/crypto/utils/asn1.js +1 -1
- package/src/crypto/utils/bitArray.js +33 -48
- package/src/crypto/utils/bn.js +1 -1
- package/src/crypto/utils/jws.js +37 -41
- package/src/crypto/utils/keyformat.js +181 -2
- package/src/crypto/utils/pem.js +1 -1
- package/src/crypto/utils/random.acvp.md +5 -5
- package/src/crypto/utils/random.js +845 -846
- package/src/crypto/utils/rsaKeygen.acvp.md +3 -2
- package/src/crypto/utils/rsaKeygen.js +6 -6
- package/src/crypto/utils/totp.js +1 -1
- package/src/crypto/utils/uuid.acvp.md +5 -5
- package/src/crypto/utils/uuid.js +11 -10
- package/src/crypto/utils/x509.js +591 -0
- package/src/crypto/wasm/aes.js +1 -1
- package/src/crypto/wasm/aes.scalar.wasm +0 -0
- package/src/crypto/wasm/argon2.js +17 -1
- package/src/crypto/wasm/argon2.scalar.wasm +0 -0
- package/src/crypto/wasm/blake2b.scalar.wasm +0 -0
- package/src/crypto/wasm/blake2b.simd.wasm +0 -0
- package/src/crypto/wasm/chacha20poly1305.scalar.wasm +0 -0
- package/src/crypto/wasm/chacha20poly1305.simd.wasm +0 -0
- package/src/crypto/wasm/cmac.scalar.wasm +0 -0
- package/src/crypto/wasm/ecc.js +3 -3
- package/src/crypto/wasm/ecc.scalar.wasm +0 -0
- package/src/crypto/wasm/ed25519.js +1 -1
- package/src/crypto/wasm/ed25519.scalar.wasm +0 -0
- package/src/crypto/wasm/hkdf.scalar.wasm +0 -0
- package/src/crypto/wasm/hmac.scalar.wasm +0 -0
- package/src/crypto/wasm/ml_dsa.js +2 -2
- package/src/crypto/wasm/ml_dsa.scalar.wasm +0 -0
- package/src/crypto/wasm/ml_dsa.simd.wasm +0 -0
- package/src/crypto/wasm/ml_kem.js +2 -2
- package/src/crypto/wasm/ml_kem.scalar.wasm +0 -0
- package/src/crypto/wasm/ml_kem.simd.wasm +0 -0
- package/src/crypto/wasm/pbkdf2.js +8 -6
- package/src/crypto/wasm/pbkdf2.scalar.wasm +0 -0
- package/src/crypto/wasm/rsa.js +6 -5
- package/src/crypto/wasm/rsa.scalar.wasm +0 -0
- package/src/crypto/wasm/runtime.js +84 -17
- package/src/crypto/wasm/sha2.scalar.wasm +0 -0
- package/src/crypto/wasm/sha3.scalar.wasm +0 -0
- package/src/crypto/wasm/sha3.simd.wasm +0 -0
- package/src/crypto/wasm/slh_dsa.js +1 -1
- package/src/crypto/wasm/slh_dsa.scalar.wasm +0 -0
- package/src/crypto/wasm/x25519.js +1 -1
- package/src/crypto/wasm/x25519.scalar.wasm +0 -0
- package/src/crypto/webcrypto/aes.js +8 -2
- package/src/crypto/webcrypto/aeskw.js +7 -2
- package/src/crypto/webcrypto/digest.js +1 -15
- package/src/crypto/webcrypto/ecc.js +2 -2
- package/src/crypto/webcrypto/ed25519.js +2 -2
- package/src/crypto/webcrypto/hmac.js +2 -2
- package/src/crypto/webcrypto/rsa.js +7 -2
- package/src/crypto/webcrypto/x25519.js +2 -2
- package/src/dom/display/animate.js +1 -1
- package/src/dom/display/fullscreen.js +1 -1
- package/src/dom/fs/download.js +1 -1
- package/src/dom/fs/fileIntake.js +192 -0
- package/src/dom/fs/fsAccess.js +2 -3
- package/src/dom/fs/indexedDB.js +1 -1
- package/src/dom/fs/remoteStore.js +1 -1
- package/src/dom/fs/storage.js +1 -1
- package/src/dom/lifecycle/idle.js +1 -1
- package/src/dom/lifecycle/visibility.js +1 -1
- package/src/dom/lifecycle/wakeLock.js +1 -1
- package/src/dom/net/ajax.js +1 -1
- package/src/dom/net/network.js +1 -1
- package/src/dom/net/sse.js +1 -1
- package/src/dom/net/webrtc.js +1 -1
- package/src/dom/net/ws.js +1 -1
- package/src/dom/query/dnd.js +56 -4
- package/src/dom/query/dom.js +1 -1
- package/src/dom/query/events.js +1 -1
- package/src/dom/query/gesture.js +1 -1
- package/src/dom/query/media.js +1 -1
- package/src/dom/query/sound.js +333 -0
- package/src/dom/rendering/chart.js +736 -663
- package/src/dom/rendering/component.js +25 -14
- package/src/dom/rendering/devtools.js +2 -2
- package/src/dom/rendering/parser.js +155 -12
- package/src/dom/rendering/render.js +14 -4
- package/src/dom/rendering/sanitize.js +11 -4
- package/src/dom/rendering/secPolicy.js +6 -4
- package/src/dom/rendering/styleSheet.js +217 -0
- package/src/dom/rendering/template.js +72 -13
- package/src/dom/rendering/themeTokens.js +542 -522
- package/src/dom/rendering/uiSession-core.js +51 -6
- package/src/dom/rendering/uiSession-direct.js +1 -1
- package/src/dom/rendering/uiSession-list.js +4 -4
- package/src/dom/rendering/uiSession.js +1 -1
- package/src/dom/rendering/virtualScroll.js +341 -341
- package/src/dom/sensors/battery.js +1 -1
- package/src/dom/sensors/geolocation.js +1 -1
- package/src/dom/sensors/networkInfo.js +1 -1
- package/src/dom/sensors/sensors.js +1 -1
- package/src/dom/sw/backgroundSync.js +1 -1
- package/src/dom/sw/cache.js +1 -1
- package/src/dom/sw/installPrompt.js +151 -0
- package/src/dom/sw/precache.js +257 -0
- package/src/dom/sw/push.js +1 -1
- package/src/dom/sw/sharedWorker.js +1 -1
- package/src/dom/sw/swUpdate.js +239 -0
- package/src/dom/utils/a11y.js +1 -1
- package/src/dom/utils/clipboard.js +56 -6
- package/src/dom/utils/entropyCollector.js +1 -1
- package/src/dom/utils/focus.js +1 -1
- package/src/dom/utils/form.js +1 -1
- package/src/dom/utils/keybindings.js +600 -574
- package/src/dom/utils/leaderElection.js +1 -1
- package/src/dom/utils/notifications.js +1 -1
- package/src/dom/utils/permissions.js +107 -107
- package/src/dom/utils/route.js +14 -2
- package/src/dom/utils/ua.js +42 -28
- package/src/dom/utils/webauthn.js +1 -1
- package/src/io/binary/reader.js +1 -1
- package/src/io/binary/writer.js +1 -1
- package/src/io/calc/bigint.js +1 -1
- package/src/io/calc/crc32.js +28 -2
- package/src/io/calc/easing.js +514 -514
- package/src/io/codec/b64.js +189 -52
- package/src/io/codec/base32.js +1 -1
- package/src/io/codec/base58.js +1 -1
- package/src/io/codec/buffer.js +1 -1
- package/src/io/codec/cbor.js +111 -18
- package/src/io/codec/csv.js +1 -1
- package/src/io/codec/hex.js +51 -6
- package/src/io/codec/mime.js +1 -1
- package/src/io/codec/msgpack.js +47 -6
- package/src/io/codec/url.js +24 -7
- package/src/io/codec/utf8.js +5 -3
- package/src/io/codec/xml.js +1 -1
- package/src/io/compress/bitstream.js +2 -2
- package/src/io/compress/brotli.js +663 -163
- package/src/io/compress/brotli_dict.js +1 -1
- package/src/io/compress/brotli_dict_words.js +1 -1
- package/src/io/compress/brotli_frame.js +1 -1
- package/src/io/compress/brotli_shared.js +7 -7
- package/src/io/compress/deflate.js +87 -53
- package/src/io/compress/gzip.js +187 -74
- package/src/io/compress/huffman.js +24 -1
- package/src/io/compress/lz4.js +45 -7
- package/src/io/compress/lz77.js +148 -63
- package/src/io/compress/lzw.js +35 -19
- package/src/io/compress/zip.js +862 -815
- package/src/io/compress/zlib.js +87 -7
- package/src/io/i18n/i18n.js +1 -1
- package/src/io/math/fixed-point.js +1 -1
- package/src/io/math/geom.js +1 -1
- package/src/io/math/interp.js +1 -1
- package/src/io/math/linalg.js +10 -4
- package/src/io/math/stats.js +1 -1
- package/src/io/structures/btree.js +1 -1
- package/src/io/structures/heap.js +1 -1
- package/src/io/structures/lruCache.js +1 -1
- package/src/io/structures/ringBuffer.js +1 -1
- package/src/io/structures/tree-walker.js +1 -1
- package/src/io/structures/trie.js +1 -1
- package/src/io/sync/abort.js +1 -1
- package/src/io/sync/atomics.js +1 -1
- package/src/io/sync/cancellable.js +1 -1
- package/src/io/sync/channel.js +1 -1
- package/src/io/sync/mutex.js +1 -1
- package/src/io/sync/semaphore.js +1 -1
- package/src/io/sync/tokenBucket.js +1 -1
- package/src/io/text/ansi.js +1 -1
- package/src/io/text/html-entities.js +1 -1
- package/src/io/time/date.js +1 -1
- package/src/io/timing/clock.js +1 -1
- package/src/io/timing/rateLimit.js +1 -1
- package/src/io/timing/scheduler.js +1 -1
- package/src/io/utils/errors.js +1 -1
- package/src/io/utils/eventBus.js +1 -1
- package/src/io/utils/signal.js +1 -1
- package/src/io/utils/valid.js +1 -1
- package/src/main.js +1 -1
- package/src/process/message.js +1 -1
- package/src/process/rpc.js +7 -3
- package/src/process/workerPool.js +11 -4
- package/src/sanity/base.js +85 -39
- package/src/sanity/lockdown-apply.js +3 -3
- package/src/sanity/lockdown.js +58 -32
- package/src/sanity/wasm-gate.js +2 -2
- package/src/typed.js +7 -3
- package/third-party/NOTICE-brotli-dictionary.txt +69 -0
- package/third-party/NOTICE-fw-wasm-crypto.txt +576 -0
- package/third-party/NOTICE-whatwg-entities.txt +44 -0
- package/types/registry.generated.d.ts +7 -1
- package/types/typed.d.ts +7 -3
- package/dist/types/crypto/utils/aes_ctr.d.ts +0 -84
- package/dist/types/crypto/utils/aes_ctr.d.ts.map +0 -1
- package/docs/api/crypto/utils/aes_ctr.md +0 -71
- package/src/crypto/utils/aes_ctr.acvp.md +0 -67
- package/src/crypto/utils/aes_ctr.js +0 -134
package/src/io/codec/b64.js
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright (c) 2026 AwaCloud SAS
|
|
2
2
|
// Author: Matthieu Bouilloux
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @description
|
|
7
7
|
* Base64 encoding and decoding utilities for converting between byte arrays and Base64 strings.
|
|
8
|
-
* Implements standard Base64 encoding (RFC 4648) with padding
|
|
8
|
+
* Implements standard Base64 encoding (RFC 4648 section 4) with padding, and
|
|
9
|
+
* the URL- and filename-safe alphabet without padding (section 5) under `url`.
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
12
|
* const { b64 } = registry.resolve('b64');
|
|
12
13
|
* const encoded = b64.fromBytes(new Uint8Array([72, 101, 108, 108, 111])); // "SGVsbG8="
|
|
13
14
|
* const decoded = b64.toBytes('SGVsbG8='); // Uint8Array [72, 101, 108, 108, 111]
|
|
14
15
|
* const valid = b64.test('SGVsbG8='); // true
|
|
16
|
+
* const token = b64.url.fromBytes(new Uint8Array([251, 255])); // "-_8"
|
|
17
|
+
* const back = b64.url.toBytes('-_8'); // Uint8Array [251, 255]
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* base64url (RFC 4648 section 5): the `-` / `_` alphabet, no padding.
|
|
22
|
+
* @typedef {object} Base64UrlAPI
|
|
23
|
+
* @property {(bytes: Uint8Array|number[]) => string} fromBytes Encode, without padding.
|
|
24
|
+
* @property {(str: string) => (Uint8Array|false)} toBytes Decode the canonical
|
|
25
|
+
* unpadded form only: `false` for any other character, a length of 1 mod 4,
|
|
26
|
+
* or non-zero unused bits in the last character (sections 3.5 and 5), so one
|
|
27
|
+
* byte string has exactly one accepted spelling.
|
|
28
|
+
* @property {(str: string) => boolean} test `true` when `toBytes` accepts `str`.
|
|
15
29
|
*/
|
|
16
30
|
|
|
17
31
|
/**
|
|
@@ -19,6 +33,7 @@
|
|
|
19
33
|
* @property {(bytes: Uint8Array|number[]) => string} fromBytes
|
|
20
34
|
* @property {(str: string) => Uint8Array} toBytes
|
|
21
35
|
* @property {(str: string) => boolean} test
|
|
36
|
+
* @property {Base64UrlAPI} url The base64url codec.
|
|
22
37
|
*/
|
|
23
38
|
export const b64 = {
|
|
24
39
|
name: 'b64',
|
|
@@ -45,21 +60,6 @@ export const b64 = {
|
|
|
45
60
|
byteToB64[b64Char.charCodeAt(m)] = m;
|
|
46
61
|
}
|
|
47
62
|
|
|
48
|
-
/**
|
|
49
|
-
* Converts a 24-bit number to 4 Base64 characters
|
|
50
|
-
* @private
|
|
51
|
-
* @param {number} num - 24-bit number to convert
|
|
52
|
-
* @returns {string} 4 Base64 characters
|
|
53
|
-
*/
|
|
54
|
-
function _numTob64(num) {
|
|
55
|
-
return (
|
|
56
|
-
b64Char[(num >> 18) & 0x3f] +
|
|
57
|
-
b64Char[(num >> 12) & 0x3f] +
|
|
58
|
-
b64Char[(num >> 6) & 0x3f] +
|
|
59
|
-
b64Char[num & 0x3f]
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
63
|
/**
|
|
64
64
|
* Converts 4 Base64 characters to a 24-bit number
|
|
65
65
|
* @private
|
|
@@ -103,37 +103,6 @@ export const b64 = {
|
|
|
103
103
|
arr.push('=');
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
/**
|
|
107
|
-
* Internal encoding implementation
|
|
108
|
-
* @private
|
|
109
|
-
* @param {Uint8Array} bytes - Bytes to encode
|
|
110
|
-
* @param {Array<string>} arr - Output array
|
|
111
|
-
* @param {number} len - Length of bytes
|
|
112
|
-
* @param {number} remain - Number of remaining bytes (0, 1, or 2)
|
|
113
|
-
* @returns {string} Base64 encoded string
|
|
114
|
-
*/
|
|
115
|
-
function _encode(bytes, arr, len, remain) {
|
|
116
|
-
len = len - remain;
|
|
117
|
-
|
|
118
|
-
for (let i = 0; i < len; i += 3) {
|
|
119
|
-
arr.push(
|
|
120
|
-
_numTob64(
|
|
121
|
-
(bytes[i] << 16) + (bytes[i + 1] << 8) + bytes[i + 2]
|
|
122
|
-
)
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
len = bytes.length;
|
|
127
|
-
|
|
128
|
-
if (remain === 1) {
|
|
129
|
-
_enc_remain1(arr, bytes[len - 1]);
|
|
130
|
-
} else if (remain === 2) {
|
|
131
|
-
_enc_remain2(arr, (bytes[len - 2] << 8) + bytes[len - 1]);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return arr.join('');
|
|
135
|
-
}
|
|
136
|
-
|
|
137
106
|
/**
|
|
138
107
|
* Decodes remaining 1 byte from Base64
|
|
139
108
|
* @private
|
|
@@ -184,6 +153,130 @@ export const b64 = {
|
|
|
184
153
|
return new Uint8Array(arr);
|
|
185
154
|
}
|
|
186
155
|
|
|
156
|
+
// ── Fast paths ──
|
|
157
|
+
//
|
|
158
|
+
// The decoder above is the reference behaviour, kept verbatim: the
|
|
159
|
+
// fast decoder below hands it every input that is not canonical
|
|
160
|
+
// base64. The encoder keeps the original arithmetic (one 24-bit
|
|
161
|
+
// number per 3 bytes, `+` of the shifted bytes, then `& 0x3f` per
|
|
162
|
+
// sextet) and the tail functions above, so every input — arrays of
|
|
163
|
+
// out-of-range numbers and malformed strings included — gives
|
|
164
|
+
// exactly the result it always gave.
|
|
165
|
+
|
|
166
|
+
/** Alphabet codes. */
|
|
167
|
+
const b64Code = Uint8Array.from(b64Char, (c) => c.charCodeAt(0));
|
|
168
|
+
|
|
169
|
+
/** Whether a `Uint16Array` stores its low byte first (it does on every current platform). */
|
|
170
|
+
const little = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
|
|
171
|
+
|
|
172
|
+
/** 12 bits -> their two alphabet codes as one 16-bit unit, in memory order. */
|
|
173
|
+
const pairCode = new Uint16Array(4096);
|
|
174
|
+
for (let v = 0; v < 4096; v++) {
|
|
175
|
+
const a = b64Code[v >> 6], b = b64Code[v & 0x3f];
|
|
176
|
+
pairCode[v] = little ? a | (b << 8) : (a << 8) | b;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Decode table: sextet value, or 64 (bit 6) for a character outside the alphabet. */
|
|
180
|
+
const sextet = new Uint8Array(256).fill(64);
|
|
181
|
+
for (let m = 0; m < 64; m++) sextet[b64Char.charCodeAt(m)] = m;
|
|
182
|
+
|
|
183
|
+
// `Uint8Array.prototype.toBase64` / `Uint8Array.fromBase64` (TC39
|
|
184
|
+
// "Uint8Array to/from base64"; JavaScriptCore, SpiderMonkey), read
|
|
185
|
+
// once: a realm without them takes the JS paths.
|
|
186
|
+
// Typed `any`: not in the ES2023 lib the type build targets.
|
|
187
|
+
const U8 = /** @type {any} */ (Uint8Array);
|
|
188
|
+
const nativeTo = typeof U8.prototype.toBase64 === 'function' ? U8.prototype.toBase64 : null;
|
|
189
|
+
const nativeFrom = typeof U8.fromBase64 === 'function' ? U8.fromBase64 : null;
|
|
190
|
+
|
|
191
|
+
// ASCII bytes decode as UTF-8 to the same characters; the platform
|
|
192
|
+
// decoder is several times faster than `String.fromCharCode`, which
|
|
193
|
+
// remains the fallback of a realm without `TextDecoder`.
|
|
194
|
+
const ascii = typeof TextDecoder === 'function' ? new TextDecoder() : null;
|
|
195
|
+
|
|
196
|
+
/** Character codes per `String.fromCharCode` call (argument-count limit). */
|
|
197
|
+
const CHUNK = 8192;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* A string from ASCII character codes.
|
|
201
|
+
* @param {Uint8Array} codes
|
|
202
|
+
* @returns {string}
|
|
203
|
+
*/
|
|
204
|
+
function _codesToString(codes) {
|
|
205
|
+
if (ascii) return ascii.decode(codes);
|
|
206
|
+
if (codes.length <= CHUNK) return String.fromCharCode.apply(null, /** @type {any} */ (codes));
|
|
207
|
+
const parts = [];
|
|
208
|
+
for (let k = 0; k < codes.length; k += CHUNK) {
|
|
209
|
+
parts.push(String.fromCharCode.apply(null, /** @type {any} */ (codes.subarray(k, k + CHUNK))));
|
|
210
|
+
}
|
|
211
|
+
return parts.join('');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Encode: the whole 3-byte groups through pair codes in a
|
|
216
|
+
* `Uint16Array` (two 12-bit halves of the original 24-bit number), the
|
|
217
|
+
* last 1-2 bytes through `_enc_remain1` / `_enc_remain2`.
|
|
218
|
+
* @param {Uint8Array|number[]} bytes
|
|
219
|
+
* @returns {string}
|
|
220
|
+
*/
|
|
221
|
+
function _encodeFast(bytes) {
|
|
222
|
+
const len = bytes.length;
|
|
223
|
+
const remain = len % 3;
|
|
224
|
+
const whole = len - remain;
|
|
225
|
+
const pairs = new Uint16Array((whole / 3) * 2);
|
|
226
|
+
for (let i = 0, j = 0; i < whole; i += 3, j += 2) {
|
|
227
|
+
const num = (bytes[i] << 16) + (bytes[i + 1] << 8) + bytes[i + 2];
|
|
228
|
+
pairs[j] = pairCode[(num >> 12) & 0xfff];
|
|
229
|
+
pairs[j + 1] = pairCode[num & 0xfff];
|
|
230
|
+
}
|
|
231
|
+
const body = _codesToString(new Uint8Array(pairs.buffer));
|
|
232
|
+
if (remain === 0) return body;
|
|
233
|
+
const tail = [];
|
|
234
|
+
if (remain === 1) _enc_remain1(tail, bytes[len - 1]);
|
|
235
|
+
else _enc_remain2(tail, (bytes[len - 2] << 8) + bytes[len - 1]);
|
|
236
|
+
return body + tail.join('');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Decode canonical base64 — length a multiple of 4, alphabet
|
|
241
|
+
* characters only, `=` only as the final one or two — or return
|
|
242
|
+
* `null` for anything else.
|
|
243
|
+
* @param {string} str
|
|
244
|
+
* @returns {Uint8Array|null}
|
|
245
|
+
*/
|
|
246
|
+
function _decodeFast(str) {
|
|
247
|
+
const len = str.length;
|
|
248
|
+
if (len % 4 !== 0) return null;
|
|
249
|
+
if (len === 0) return new Uint8Array(0);
|
|
250
|
+
let pad = 0;
|
|
251
|
+
if (str.charCodeAt(len - 1) === 61) pad = str.charCodeAt(len - 2) === 61 ? 2 : 1;
|
|
252
|
+
else if (str.charCodeAt(len - 2) === 61) return null; // "x=y": the old decoder reads it its own way
|
|
253
|
+
const out = new Uint8Array((len / 4) * 3 - pad);
|
|
254
|
+
const full = pad ? len - 4 : len;
|
|
255
|
+
let bad = 0, wide = 0, j = 0;
|
|
256
|
+
for (let i = 0; i < full; i += 4) {
|
|
257
|
+
const a = str.charCodeAt(i), b = str.charCodeAt(i + 1), c = str.charCodeAt(i + 2), d = str.charCodeAt(i + 3);
|
|
258
|
+
wide |= a | b | c | d;
|
|
259
|
+
const sa = sextet[a], sb = sextet[b], sc = sextet[c], sd = sextet[d];
|
|
260
|
+
bad |= sa | sb | sc | sd;
|
|
261
|
+
const num = (sa << 18) | (sb << 12) | (sc << 6) | sd;
|
|
262
|
+
out[j++] = num >> 16;
|
|
263
|
+
out[j++] = num >> 8;
|
|
264
|
+
out[j++] = num;
|
|
265
|
+
}
|
|
266
|
+
if (pad) {
|
|
267
|
+
const a = str.charCodeAt(full), b = str.charCodeAt(full + 1);
|
|
268
|
+
const c = pad === 1 ? str.charCodeAt(full + 2) : 65; // 'A': a zero sextet
|
|
269
|
+
wide |= a | b | c;
|
|
270
|
+
const sa = sextet[a], sb = sextet[b], sc = sextet[c];
|
|
271
|
+
bad |= sa | sb | sc;
|
|
272
|
+
out[j++] = (sa << 2) | (sb >> 4);
|
|
273
|
+
if (pad === 1) out[j] = (sb << 4) | (sc >> 2);
|
|
274
|
+
}
|
|
275
|
+
// A code above 255 indexes past the table (undefined, i.e. 0 in
|
|
276
|
+
// the arithmetic): `wide` catches it, `bad` every other outsider.
|
|
277
|
+
return (bad & 64) || wide > 255 ? null : out;
|
|
278
|
+
}
|
|
279
|
+
|
|
187
280
|
/**
|
|
188
281
|
* Encodes a byte array to a Base64 string
|
|
189
282
|
*
|
|
@@ -195,8 +288,8 @@ export const b64 = {
|
|
|
195
288
|
* const encoded = fromBytes(bytes); // "SGVsbG8="
|
|
196
289
|
*/
|
|
197
290
|
const fromBytes = function (bytes) {
|
|
198
|
-
|
|
199
|
-
return
|
|
291
|
+
if (nativeTo && bytes instanceof Uint8Array) return nativeTo.call(bytes);
|
|
292
|
+
return _encodeFast(bytes);
|
|
200
293
|
};
|
|
201
294
|
|
|
202
295
|
/**
|
|
@@ -210,7 +303,23 @@ export const b64 = {
|
|
|
210
303
|
* console.log(decoded); // Uint8Array [72, 101, 108, 108, 111]
|
|
211
304
|
*/
|
|
212
305
|
const toBytes = function (str) {
|
|
213
|
-
return _decode(str, [], 0, str.length, 0);
|
|
306
|
+
if (typeof str !== 'string') return _decode(str, [], 0, /** @type {any} */ (str).length, 0);
|
|
307
|
+
const len = str.length;
|
|
308
|
+
if (nativeFrom && len % 4 === 0 && len > 0) {
|
|
309
|
+
// The native decoder also accepts whitespace and missing
|
|
310
|
+
// padding, which the old decoder reads differently: its
|
|
311
|
+
// result is kept only when it has the canonical length, which
|
|
312
|
+
// no such input can reach (each skipped character drops
|
|
313
|
+
// output bits), and anything it rejects goes on below.
|
|
314
|
+
const last = str.charCodeAt(len - 1) === 61, prev = str.charCodeAt(len - 2) === 61;
|
|
315
|
+
if (last || !prev) {
|
|
316
|
+
try {
|
|
317
|
+
const r = nativeFrom(str);
|
|
318
|
+
if (r.length === (len / 4) * 3 - (last ? (prev ? 2 : 1) : 0)) return r;
|
|
319
|
+
} catch { /* not canonical: the JS paths below */ }
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return _decodeFast(str) || _decode(str, [], 0, len, 0);
|
|
214
323
|
};
|
|
215
324
|
|
|
216
325
|
/**
|
|
@@ -230,6 +339,34 @@ export const b64 = {
|
|
|
230
339
|
return /^(?=(.{4})*$)[A-Za-z0-9+/]*={0,2}$/.test(str);
|
|
231
340
|
};
|
|
232
341
|
|
|
233
|
-
|
|
342
|
+
// ── base64url (RFC 4648 section 5) ──────────────────────────────
|
|
343
|
+
|
|
344
|
+
const _B64U = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
345
|
+
|
|
346
|
+
/** @param {Uint8Array|number[]} bytes @returns {string} */
|
|
347
|
+
const urlFromBytes = function (bytes) {
|
|
348
|
+
return fromBytes(bytes).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
/** @param {string} s @returns {boolean} the canonical unpadded form */
|
|
352
|
+
const urlTest = function (s) {
|
|
353
|
+
if (typeof s !== 'string' || !/^[A-Za-z0-9\-_]*$/.test(s)) return false;
|
|
354
|
+
const rem = s.length % 4;
|
|
355
|
+
if (rem === 1) return false;
|
|
356
|
+
if (rem === 0) return true;
|
|
357
|
+
const unusedBits = rem === 2 ? 4 : 2;
|
|
358
|
+
return (_B64U.indexOf(s[s.length - 1]) & ((1 << unusedBits) - 1)) === 0;
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
/** @param {string} s @returns {Uint8Array|false} */
|
|
362
|
+
const urlToBytes = function (s) {
|
|
363
|
+
if (!urlTest(s)) return false;
|
|
364
|
+
const std = s.replace(/-/g, '+').replace(/_/g, '/');
|
|
365
|
+
return toBytes(std + '='.repeat((4 - (s.length % 4)) % 4));
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
const url = { fromBytes: urlFromBytes, toBytes: urlToBytes, test: urlTest };
|
|
369
|
+
|
|
370
|
+
return { fromBytes, toBytes, test, url };
|
|
234
371
|
}
|
|
235
372
|
};
|
package/src/io/codec/base32.js
CHANGED
package/src/io/codec/base58.js
CHANGED
package/src/io/codec/buffer.js
CHANGED
package/src/io/codec/cbor.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright (c) 2026 AwaCloud SAS
|
|
2
2
|
// Author: Matthieu Bouilloux
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
@@ -43,7 +43,7 @@ import { utf8 } from './utf8.js';
|
|
|
43
43
|
/**
|
|
44
44
|
* @typedef {object} CborAPI
|
|
45
45
|
* @property {(value: unknown, options?: { deterministic?: boolean }) => Uint8Array} encode
|
|
46
|
-
* @property {(bytes: Uint8Array, options?: { useMap?: boolean }) => unknown} decode
|
|
46
|
+
* @property {(bytes: Uint8Array, options?: { useMap?: boolean, maxDepth?: number }) => unknown} decode
|
|
47
47
|
* @property {new (tag: number, value: unknown) => CborTagged} Tagged
|
|
48
48
|
* @property {new (value: number) => CborSimple} Simple
|
|
49
49
|
*/
|
|
@@ -295,6 +295,14 @@ export const cbor = {
|
|
|
295
295
|
else writeHead(out, 1, -1 - val);
|
|
296
296
|
return;
|
|
297
297
|
}
|
|
298
|
+
// Every safe integer is an integer on the wire (RFC 8949 §3.1,
|
|
299
|
+
// App. A: 1e12 is 0x1b000000e8d4a51000, D24); past 2^53 a
|
|
300
|
+
// number is no longer exact and stays a float.
|
|
301
|
+
if (Number.isSafeInteger(val)) {
|
|
302
|
+
if (val >= 0) writeHead(out, 0, BigInt(val));
|
|
303
|
+
else writeHead(out, 1, -1n - BigInt(val));
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
298
306
|
encodeFloatShortest(val, out);
|
|
299
307
|
return;
|
|
300
308
|
}
|
|
@@ -359,6 +367,19 @@ export const cbor = {
|
|
|
359
367
|
throw new Error(`CBOR: cannot encode value of type ${typeof val}`);
|
|
360
368
|
}
|
|
361
369
|
|
|
370
|
+
/**
|
|
371
|
+
* Set an own enumerable property, `__proto__` included: assigning
|
|
372
|
+
* `obj.__proto__ = v` would replace the object's prototype with a
|
|
373
|
+
* decoded value instead of storing it. Every other key assigns.
|
|
374
|
+
*/
|
|
375
|
+
function _setOwn(obj, key, value) {
|
|
376
|
+
if (key === '__proto__') {
|
|
377
|
+
Object.defineProperty(obj, key, { value, writable: true, enumerable: true, configurable: true });
|
|
378
|
+
} else {
|
|
379
|
+
obj[key] = value;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
362
383
|
/**
|
|
363
384
|
* Encode a JS value to a CBOR byte array.
|
|
364
385
|
* @param {any} value
|
|
@@ -377,6 +398,26 @@ export const cbor = {
|
|
|
377
398
|
|
|
378
399
|
// ---------- decoder ----------
|
|
379
400
|
|
|
401
|
+
/** Default nesting limit of `decode` (arrays, maps, tags). */
|
|
402
|
+
const DEFAULT_MAX_DEPTH = 512;
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Enter one nesting level: past `maxDepth` the decode throws instead
|
|
406
|
+
* of recursing until the engine's stack overflows (audit A5; a
|
|
407
|
+
* 100 000-deep array is a few hundred kilobytes of input).
|
|
408
|
+
*/
|
|
409
|
+
function enter(ctx) {
|
|
410
|
+
if (++ctx.depth > ctx.maxDepth) throw new Error('CBOR: nesting deeper than maxDepth (' + ctx.maxDepth + ')');
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function maxDepthOf(options) {
|
|
414
|
+
const d = options && options.maxDepth;
|
|
415
|
+
if (d === undefined || d === null) return DEFAULT_MAX_DEPTH;
|
|
416
|
+
if (!Number.isInteger(d) || d < 1) throw new RangeError('cbor.decode: maxDepth must be a positive integer');
|
|
417
|
+
return d;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
|
|
380
421
|
function readArgument(ctx, info) {
|
|
381
422
|
const { view } = ctx;
|
|
382
423
|
if (info < 24) return info;
|
|
@@ -394,22 +435,54 @@ export const cbor = {
|
|
|
394
435
|
}
|
|
395
436
|
|
|
396
437
|
function decodeMap(ctx, n) {
|
|
438
|
+
enter(ctx);
|
|
397
439
|
if (ctx.useMap) {
|
|
398
440
|
const m = new Map();
|
|
399
441
|
for (let i = 0; i < n; i++) {
|
|
400
|
-
const k =
|
|
401
|
-
m.set(k,
|
|
442
|
+
const k = decodeItem(ctx);
|
|
443
|
+
m.set(k, decodeItem(ctx));
|
|
402
444
|
}
|
|
445
|
+
ctx.depth--;
|
|
403
446
|
return m;
|
|
404
447
|
}
|
|
405
|
-
const obj =
|
|
448
|
+
const obj = Object.create(null); // null prototype: no inherited key collides with a decoded one (D9 G7)
|
|
406
449
|
for (let i = 0; i < n; i++) {
|
|
407
|
-
const k =
|
|
408
|
-
obj
|
|
450
|
+
const k = decodeItem(ctx);
|
|
451
|
+
_setOwn(obj, k, decodeItem(ctx));
|
|
409
452
|
}
|
|
453
|
+
ctx.depth--;
|
|
410
454
|
return obj;
|
|
411
455
|
}
|
|
412
456
|
|
|
457
|
+
/**
|
|
458
|
+
* A data item: `decodeValue`, where a break stop code (0xff) is not
|
|
459
|
+
* well-formed (RFC 8949 §3.2.1: a break only ends an indefinite-length
|
|
460
|
+
* item; App. F). The indefinite loops read their break themselves.
|
|
461
|
+
*/
|
|
462
|
+
function decodeItem(ctx) {
|
|
463
|
+
const v = decodeValue(ctx);
|
|
464
|
+
if (v === BREAK) throw new Error('CBOR: break outside an indefinite-length item');
|
|
465
|
+
return v;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* The next chunk of an indefinite-length string of `major`, or BREAK:
|
|
470
|
+
* a chunk is a definite-length string of the same major type (RFC 8949
|
|
471
|
+
* §3.2.3), not a nested indefinite one.
|
|
472
|
+
*/
|
|
473
|
+
function decodeChunk(ctx, major) {
|
|
474
|
+
if (ctx.offset >= ctx.bytes.length) throw new Error('CBOR: unexpected end of input');
|
|
475
|
+
const b = ctx.bytes[ctx.offset];
|
|
476
|
+
if (b === 0xff) { ctx.offset++; return BREAK; }
|
|
477
|
+
if ((b >> 5) !== major || (b & 0x1f) === 31) throw new Error('CBOR: an indefinite-length string chunk must be a definite-length string of the same type');
|
|
478
|
+
return decodeValue(ctx);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/** Throw unless `n` bytes remain at the offset (App. F: short data). */
|
|
482
|
+
function need(ctx, n) {
|
|
483
|
+
if (!(n <= ctx.bytes.length - ctx.offset)) throw new Error('CBOR: unexpected end of input');
|
|
484
|
+
}
|
|
485
|
+
|
|
413
486
|
function decodeValue(ctx) {
|
|
414
487
|
const { view, bytes } = ctx;
|
|
415
488
|
if (ctx.offset >= bytes.length) throw new Error('CBOR: unexpected end of input');
|
|
@@ -423,7 +496,12 @@ export const cbor = {
|
|
|
423
496
|
if (info === 22) return null;
|
|
424
497
|
if (info === 23) return undefined;
|
|
425
498
|
if (info < 24) return new Simple(info);
|
|
426
|
-
if (info === 24) {
|
|
499
|
+
if (info === 24) {
|
|
500
|
+
const v = view.getUint8(ctx.offset); ctx.offset += 1;
|
|
501
|
+
// RFC 8949 §3.3: simple values 0-31 have a one-byte form only.
|
|
502
|
+
if (v < 32) throw new Error('CBOR: simple value ' + v + ' in a two-byte encoding');
|
|
503
|
+
return new Simple(v);
|
|
504
|
+
}
|
|
427
505
|
if (info === 25) { const h = view.getUint16(ctx.offset, false); ctx.offset += 2; return float16ToFloat64(h); }
|
|
428
506
|
if (info === 26) { const f = view.getFloat32(ctx.offset, false); ctx.offset += 4; return f; }
|
|
429
507
|
if (info === 27) { const f = view.getFloat64(ctx.offset, false); ctx.offset += 8; return f; }
|
|
@@ -435,7 +513,7 @@ export const cbor = {
|
|
|
435
513
|
if (major === 2) {
|
|
436
514
|
const parts = [];
|
|
437
515
|
for (; ;) {
|
|
438
|
-
const next =
|
|
516
|
+
const next = decodeChunk(ctx, 2);
|
|
439
517
|
if (next === BREAK) break;
|
|
440
518
|
if (!(next instanceof Uint8Array)) throw new Error('CBOR: expected byte string chunk');
|
|
441
519
|
parts.push(next);
|
|
@@ -445,7 +523,7 @@ export const cbor = {
|
|
|
445
523
|
if (major === 3) {
|
|
446
524
|
let s = '';
|
|
447
525
|
for (; ;) {
|
|
448
|
-
const next =
|
|
526
|
+
const next = decodeChunk(ctx, 3);
|
|
449
527
|
if (next === BREAK) break;
|
|
450
528
|
if (typeof next !== 'string') throw new Error('CBOR: expected text string chunk');
|
|
451
529
|
s += next;
|
|
@@ -453,30 +531,35 @@ export const cbor = {
|
|
|
453
531
|
return s;
|
|
454
532
|
}
|
|
455
533
|
if (major === 4) {
|
|
534
|
+
enter(ctx);
|
|
456
535
|
const arr = [];
|
|
457
536
|
for (; ;) {
|
|
458
537
|
const next = decodeValue(ctx);
|
|
459
538
|
if (next === BREAK) break;
|
|
460
539
|
arr.push(next);
|
|
461
540
|
}
|
|
541
|
+
ctx.depth--;
|
|
462
542
|
return arr;
|
|
463
543
|
}
|
|
464
544
|
if (major === 5) {
|
|
545
|
+
enter(ctx);
|
|
465
546
|
if (ctx.useMap) {
|
|
466
547
|
const m = new Map();
|
|
467
548
|
for (; ;) {
|
|
468
549
|
const k = decodeValue(ctx);
|
|
469
550
|
if (k === BREAK) break;
|
|
470
|
-
m.set(k,
|
|
551
|
+
m.set(k, decodeItem(ctx));
|
|
471
552
|
}
|
|
553
|
+
ctx.depth--;
|
|
472
554
|
return m;
|
|
473
555
|
}
|
|
474
|
-
const obj =
|
|
556
|
+
const obj = Object.create(null); // null prototype: no inherited key collides with a decoded one (D9 G7)
|
|
475
557
|
for (; ;) {
|
|
476
558
|
const k = decodeValue(ctx);
|
|
477
559
|
if (k === BREAK) break;
|
|
478
|
-
obj
|
|
560
|
+
_setOwn(obj, k, decodeItem(ctx));
|
|
479
561
|
}
|
|
562
|
+
ctx.depth--;
|
|
480
563
|
return obj;
|
|
481
564
|
}
|
|
482
565
|
throw new Error(`CBOR: indefinite length not allowed for major ${major}`);
|
|
@@ -491,25 +574,31 @@ export const cbor = {
|
|
|
491
574
|
return -1 - arg;
|
|
492
575
|
case 2: {
|
|
493
576
|
const n = Number(arg);
|
|
577
|
+
need(ctx, n);
|
|
494
578
|
const out = bytes.slice(ctx.offset, ctx.offset + n);
|
|
495
579
|
ctx.offset += n;
|
|
496
580
|
return out;
|
|
497
581
|
}
|
|
498
582
|
case 3: {
|
|
499
583
|
const n = Number(arg);
|
|
584
|
+
need(ctx, n);
|
|
500
585
|
const s = utf8.fromBytes(bytes.subarray(ctx.offset, ctx.offset + n));
|
|
501
586
|
ctx.offset += n;
|
|
502
587
|
return s;
|
|
503
588
|
}
|
|
504
589
|
case 4: {
|
|
505
590
|
const n = Number(arg);
|
|
591
|
+
enter(ctx);
|
|
506
592
|
const arr = new Array(n);
|
|
507
|
-
for (let i = 0; i < n; i++) arr[i] =
|
|
593
|
+
for (let i = 0; i < n; i++) arr[i] = decodeItem(ctx);
|
|
594
|
+
ctx.depth--;
|
|
508
595
|
return arr;
|
|
509
596
|
}
|
|
510
597
|
case 5: return decodeMap(ctx, Number(arg));
|
|
511
598
|
case 6: {
|
|
512
|
-
|
|
599
|
+
enter(ctx);
|
|
600
|
+
const inner = decodeItem(ctx);
|
|
601
|
+
ctx.depth--;
|
|
513
602
|
const tag = typeof arg === 'bigint' ? Number(arg) : arg;
|
|
514
603
|
if (tag === 2 && inner instanceof Uint8Array) {
|
|
515
604
|
let n = 0n;
|
|
@@ -530,9 +619,11 @@ export const cbor = {
|
|
|
530
619
|
/**
|
|
531
620
|
* Decode a CBOR byte array into a JS value.
|
|
532
621
|
* @param {Uint8Array} bytes
|
|
533
|
-
* @param {{useMap?: boolean}} [options]
|
|
622
|
+
* @param {{useMap?: boolean, maxDepth?: number}} [options]
|
|
534
623
|
* `useMap` : return `Map` instances instead of plain objects
|
|
535
624
|
* (preserves non-string keys and insertion order).
|
|
625
|
+
* `maxDepth` : nesting limit of arrays, maps and tags (default
|
|
626
|
+
* 512); a deeper item throws.
|
|
536
627
|
* @returns {any}
|
|
537
628
|
*/
|
|
538
629
|
function decode(bytes, options) {
|
|
@@ -540,9 +631,11 @@ export const cbor = {
|
|
|
540
631
|
bytes,
|
|
541
632
|
view: new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength),
|
|
542
633
|
offset: 0,
|
|
543
|
-
useMap: !!(options && options.useMap)
|
|
634
|
+
useMap: !!(options && options.useMap),
|
|
635
|
+
depth: 0,
|
|
636
|
+
maxDepth: maxDepthOf(options),
|
|
544
637
|
};
|
|
545
|
-
return
|
|
638
|
+
return decodeItem(ctx);
|
|
546
639
|
}
|
|
547
640
|
|
|
548
641
|
return { encode, decode, Tagged, Simple };
|
package/src/io/codec/csv.js
CHANGED
package/src/io/codec/hex.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright (c) 2026 AwaCloud SAS
|
|
2
2
|
// Author: Matthieu Bouilloux
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
@@ -51,6 +51,49 @@ export const hex = {
|
|
|
51
51
|
if (i >= 10) charToNibble['ABCDEF'.charCodeAt(i - 10)] = i;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/** The 16 digit codes. */
|
|
55
|
+
const hexCode = Uint8Array.from(hexChar, (c) => c.charCodeAt(0));
|
|
56
|
+
|
|
57
|
+
/** Whether a `Uint16Array` stores its low byte first (it does on every current platform). */
|
|
58
|
+
const little = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
|
|
59
|
+
|
|
60
|
+
/** Byte -> its two digit codes as one 16-bit unit, in memory order. */
|
|
61
|
+
const pairCode = new Uint16Array(256);
|
|
62
|
+
for (let b = 0; b < 256; b++) {
|
|
63
|
+
const hi = hexCode[b >> 4], lo = hexCode[b & 0x0f];
|
|
64
|
+
pairCode[b] = little ? hi | (lo << 8) : (hi << 8) | lo;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// `Uint8Array.prototype.toHex` (TC39 "Uint8Array to/from base64";
|
|
68
|
+
// JavaScriptCore, SpiderMonkey) gives the same lowercase string;
|
|
69
|
+
// read once, so a realm without it takes the JS path below.
|
|
70
|
+
// Typed `any`: not in the ES2023 lib the type build targets.
|
|
71
|
+
const U8P = /** @type {any} */ (Uint8Array.prototype);
|
|
72
|
+
const nativeToHex = typeof U8P.toHex === 'function' ? U8P.toHex : null;
|
|
73
|
+
|
|
74
|
+
// ASCII bytes decode as UTF-8 to the same characters; the platform
|
|
75
|
+
// decoder is several times faster than `String.fromCharCode`, which
|
|
76
|
+
// remains the fallback of a realm without `TextDecoder`.
|
|
77
|
+
const ascii = typeof TextDecoder === 'function' ? new TextDecoder() : null;
|
|
78
|
+
|
|
79
|
+
/** Character codes per `String.fromCharCode` call (argument-count limit). */
|
|
80
|
+
const CHUNK = 8192;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A string from ASCII character codes.
|
|
84
|
+
* @param {Uint8Array} codes
|
|
85
|
+
* @returns {string}
|
|
86
|
+
*/
|
|
87
|
+
function _codesToString(codes) {
|
|
88
|
+
if (ascii) return ascii.decode(codes);
|
|
89
|
+
if (codes.length <= CHUNK) return String.fromCharCode.apply(null, /** @type {any} */ (codes));
|
|
90
|
+
const parts = [];
|
|
91
|
+
for (let k = 0; k < codes.length; k += CHUNK) {
|
|
92
|
+
parts.push(String.fromCharCode.apply(null, /** @type {any} */ (codes.subarray(k, k + CHUNK))));
|
|
93
|
+
}
|
|
94
|
+
return parts.join('');
|
|
95
|
+
}
|
|
96
|
+
|
|
54
97
|
/**
|
|
55
98
|
* Converts a hexadecimal string to a byte array.
|
|
56
99
|
* Accepts upper- or lowercase hex digits (0-9, a-f, A-F).
|
|
@@ -98,11 +141,13 @@ export const hex = {
|
|
|
98
141
|
* console.log(hex); // "48656c6c6f"
|
|
99
142
|
*/
|
|
100
143
|
const fromBytes = (bytes) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
144
|
+
if (nativeToHex && bytes instanceof Uint8Array) return nativeToHex.call(bytes);
|
|
145
|
+
const n = bytes.length;
|
|
146
|
+
const pairs = new Uint16Array(n);
|
|
147
|
+
// `& 0xff` keeps the old per-byte result for any array element
|
|
148
|
+
// (out-of-range numbers, holes): `(b & 0xf0) >> 4` and `b & 0x0f`.
|
|
149
|
+
for (let i = 0; i < n; i++) pairs[i] = pairCode[bytes[i] & 0xff];
|
|
150
|
+
return _codesToString(new Uint8Array(pairs.buffer));
|
|
106
151
|
};
|
|
107
152
|
|
|
108
153
|
/**
|
package/src/io/codec/mime.js
CHANGED