{"_id":"@edison-manrique/sha2-wasm","_rev":"7-99890129766cafac4f9d2bf36e051ae3","name":"@edison-manrique/sha2-wasm","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"@edison-manrique/sha2-wasm","version":"1.0.0","keywords":["wasm","webassembly","sha2","sha256","sha512","hmac","hmac-sha256","hmac-sha512","assemblyscript","crypto"],"author":{"name":"Edison Manrique"},"license":"Apache-2.0","_id":"@edison-manrique/sha2-wasm@1.0.0","maintainers":[{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"}],"homepage":"https://github.com/edison-manrique/sha2-wasm#readme","bugs":{"url":"https://github.com/edison-manrique/sha2-wasm/issues"},"dist":{"shasum":"919da9b3da09ee992ed6a88930b19cacd7310e83","tarball":"https://registry.npmjs.org/@edison-manrique/sha2-wasm/-/sha2-wasm-1.0.0.tgz","fileCount":12,"integrity":"sha512-5KyhIockPCdMFRvmkx6qnmzDwmduQPIJn7P/boH+XFMMsOGlWmU9a3SFJZabBY24Out3Og69dUtfbFafb1l0qg==","signatures":[{"sig":"MEYCIQDlHsgUDlRwWbn//U6Hmxc87uDDBr4E6jTBRhFdypbsqAIhAMxbjPUhTCLvAHqLjehWyk/WQSqQt7kDIMRNmvWaNx1M","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":76427},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"7da5f8ab7725fa61a89e85c07558806c34e814ac","scripts":{"test":"bun test test/index.test.ts","build":"bun run asbuild && bun run build:ts","asbuild":"asc assembly/index.ts --target release","build:ts":"esbuild src/index.ts --bundle --format=esm --minify --platform=browser --outfile=dist/index.js && tsc --emitDeclarationOnly","examples":"bun examples/server.ts","test:stress":"bun test test/stress.test.ts","asbuild:debug":"asc assembly/index.ts --target debug","prepublishOnly":"bun run build"},"_npmUser":{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"},"repository":{"url":"git+ssh://git@github.com/edison-manrique/sha2-wasm.git","type":"git"},"_npmVersion":"11.13.0","description":"Implementación de alto rendimiento de SHA-2 (SHA-256 / SHA-512 / HMAC) en AssemblyScript / WebAssembly con un envoltorio modular en TypeScript sin asignación de memoria (zero-allocation).","directories":{},"_nodeVersion":"22.15.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/sha2-wasm_1.0.0_1785150305744_0.3486117404338225","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@edison-manrique/sha2-wasm","version":"1.0.1","keywords":["wasm","webassembly","sha2","sha256","sha512","hmac","hmac-sha256","hmac-sha512","assemblyscript","crypto"],"author":{"name":"Edison Manrique"},"license":"Apache-2.0","_id":"@edison-manrique/sha2-wasm@1.0.1","maintainers":[{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"}],"homepage":"https://github.com/edison-manrique/sha2-wasm#readme","bugs":{"url":"https://github.com/edison-manrique/sha2-wasm/issues"},"dist":{"shasum":"612ab23e90b8443b7dc7315d0c60215a764c077e","tarball":"https://registry.npmjs.org/@edison-manrique/sha2-wasm/-/sha2-wasm-1.0.1.tgz","fileCount":12,"integrity":"sha512-6/dThhtYtLM11A4YLJueSRUk0oyk19FWCm+vc4Z+V4qXvsH6XZu8NKUUZNb0A7UD3tx9rclOVdkWrcKJaXIedQ==","signatures":[{"sig":"MEQCIEHg3aK6Utk5oVKsu1XsebAbQvJzsiA7eAYcdc+8ak6dAiBYuhO2QpEIcDkcakguw7tVHU3dirLM2KAE0RZ8rFmY/w==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":76427},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"5ee49e78ea9d5e37ba5cf9c10d8052154866f9ba","scripts":{"test":"bun test test/index.test.ts","build":"bun run asbuild && bun run build:ts","asbuild":"asc assembly/index.ts --target release","build:ts":"esbuild src/index.ts --bundle --format=esm --minify --platform=browser --outfile=dist/index.js && tsc --emitDeclarationOnly","examples":"bun examples/server.ts","test:stress":"bun test test/stress.test.ts","asbuild:debug":"asc assembly/index.ts --target debug","prepublishOnly":"bun run build"},"_npmUser":{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"},"repository":{"url":"git+ssh://git@github.com/edison-manrique/sha2-wasm.git","type":"git"},"_npmVersion":"11.13.0","description":"Implementación de alto rendimiento de SHA-2 (SHA-256 / SHA-512 / HMAC) en AssemblyScript / WebAssembly con un envoltorio modular en TypeScript sin asignación de memoria (zero-allocation).","directories":{},"_nodeVersion":"22.15.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/sha2-wasm_1.0.1_1785151145123_0.7384246618628418","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@edison-manrique/sha2-wasm","version":"1.0.2","keywords":["wasm","webassembly","sha2","sha256","sha512","hmac","hmac-sha256","hmac-sha512","assemblyscript","crypto"],"author":{"name":"Edison Manrique"},"license":"Apache-2.0","_id":"@edison-manrique/sha2-wasm@1.0.2","maintainers":[{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"}],"homepage":"https://github.com/edison-manrique/sha2-wasm#readme","bugs":{"url":"https://github.com/edison-manrique/sha2-wasm/issues"},"dist":{"shasum":"2f53f71fae018dc2139620e9ee096ba5595b264b","tarball":"https://registry.npmjs.org/@edison-manrique/sha2-wasm/-/sha2-wasm-1.0.2.tgz","fileCount":12,"integrity":"sha512-bQjSLtoxtIeFUpnFUXnvoPh9IbA5LONrdYSy+WEvs+PAsZfFsQ1GDp1IX+lg3pRPBC6rydDHSX4urHk7RF0cQQ==","signatures":[{"sig":"MEUCIQC106QIv2lq2hsTFcdM7+2oElVfng8EHkDhwFU+qdqnNQIgVIcUSIBSDB38hs2n773Df19kRknwThHOFiO0RD0zVY0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":76512},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"8d722d2706b2fa6c895979f849328616e11c25c6","scripts":{"test":"bun test test/index.test.ts","build":"bun run asbuild && bun run build:ts","asbuild":"asc assembly/index.ts --target release","build:ts":"esbuild src/index.ts --bundle --format=esm --minify --platform=browser --outfile=dist/index.js && tsc --emitDeclarationOnly","examples":"bun examples/server.ts","test:stress":"bun test test/stress.test.ts","asbuild:debug":"asc assembly/index.ts --target debug","prepublishOnly":"bun run build"},"_npmUser":{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"},"repository":{"url":"git+ssh://git@github.com/edison-manrique/sha2-wasm.git","type":"git"},"_npmVersion":"11.13.0","description":"Implementación de alto rendimiento de SHA-2 (SHA-256 / SHA-512 / HMAC) en AssemblyScript / WebAssembly con un envoltorio modular en TypeScript sin asignación de memoria (zero-allocation).","directories":{},"_nodeVersion":"22.15.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/sha2-wasm_1.0.2_1785151856170_0.6485792559011812","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@edison-manrique/sha2-wasm","version":"1.0.3","keywords":["wasm","webassembly","sha2","sha256","sha512","hmac","hmac-sha256","hmac-sha512","assemblyscript","crypto"],"author":{"name":"Edison Manrique"},"license":"Apache-2.0","_id":"@edison-manrique/sha2-wasm@1.0.3","maintainers":[{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"}],"homepage":"https://github.com/edison-manrique/sha2-wasm#readme","bugs":{"url":"https://github.com/edison-manrique/sha2-wasm/issues"},"dist":{"shasum":"4a9717f7fb5c3bad2d2bcabe8353719b168e0ae7","tarball":"https://registry.npmjs.org/@edison-manrique/sha2-wasm/-/sha2-wasm-1.0.3.tgz","fileCount":12,"integrity":"sha512-rdHZv62Y3+ebuzoQgJNFFp616HMVZHjiodPItbKkw6O53rrmS/48YGhk3U1PPTgAXkKOA7VRrTgM7w2s9ee83g==","signatures":[{"sig":"MEUCIBUF5/BqzcJfMd6vf3AoPHXWPP+yjgm4mgR51Q0YVB13AiEAy132nbqRW7stqKWNiu/b5aTdgYvXm75ARrCGXxbXyiY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":76529},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"64ef88b478443cae14bdf071e709e6aefee7e0ae","scripts":{"test":"bun test test/index.test.ts","build":"bun run asbuild && bun run build:ts","asbuild":"asc assembly/index.ts --target release","build:ts":"esbuild src/index.ts --bundle --format=esm --minify --platform=browser --outfile=dist/index.js && tsc --emitDeclarationOnly","examples":"bun examples/server.ts","test:stress":"bun test test/stress.test.ts","asbuild:debug":"asc assembly/index.ts --target debug","prepublishOnly":"bun run build"},"_npmUser":{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"},"repository":{"url":"git+ssh://git@github.com/edison-manrique/sha2-wasm.git","type":"git"},"_npmVersion":"11.13.0","description":"Implementación de alto rendimiento de SHA-2 (SHA-256 / SHA-512 / HMAC) en AssemblyScript / WebAssembly con un envoltorio modular en TypeScript sin asignación de memoria (zero-allocation).","directories":{},"_nodeVersion":"22.15.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/sha2-wasm_1.0.3_1785152018388_0.8133683689760309","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"@edison-manrique/sha2-wasm","version":"1.0.4","keywords":["wasm","webassembly","sha2","sha256","sha512","hmac","hmac-sha256","hmac-sha512","assemblyscript","crypto"],"author":{"name":"Edison Manrique"},"license":"Apache-2.0","_id":"@edison-manrique/sha2-wasm@1.0.4","maintainers":[{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"}],"homepage":"https://github.com/edison-manrique/sha2-wasm#readme","bugs":{"url":"https://github.com/edison-manrique/sha2-wasm/issues"},"dist":{"shasum":"1d0880057ddce1e773136056248a2fbf1a64edd7","tarball":"https://registry.npmjs.org/@edison-manrique/sha2-wasm/-/sha2-wasm-1.0.4.tgz","fileCount":12,"integrity":"sha512-FtIF8DXm1G3cg+qDfmnTMClpoBK0+Xcm/LKfsdL0Grsdk5mbZOGrMAajJO9cNLVbkt9dLdpxQg5iKxQhts/8TQ==","signatures":[{"sig":"MEUCIEVhA1mcYkHqP6dIZJMOqYY+ruvwZNYFqu0CyBMQxFnvAiEA8qqQ06OvdP7u452oZm+0RFGH8iy1MjdCdTr14smHCIo=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":76532},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"5e0e024583475cf565c636f8d01d9832945ecde3","scripts":{"test":"bun test test/index.test.ts","build":"bun run build:as && bun run build:ts","build:as":"asc assembly/index.ts --target release","build:ts":"esbuild src/index.ts --bundle --format=esm --minify --platform=browser --outfile=dist/index.js && tsc --emitDeclarationOnly","examples":"bun examples/server.ts","test:stress":"bun test test/stress.test.ts","build:as:debug":"asc assembly/index.ts --target debug","prepublishOnly":"bun run build"},"_npmUser":{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"},"repository":{"url":"git+ssh://git@github.com/edison-manrique/sha2-wasm.git","type":"git"},"_npmVersion":"11.13.0","description":"Implementación de alto rendimiento de SHA-2 (SHA-256 / SHA-512 / HMAC) en AssemblyScript / WebAssembly con un envoltorio modular en TypeScript sin asignación de memoria (zero-allocation).","directories":{},"_nodeVersion":"22.15.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/sha2-wasm_1.0.4_1785173745890_0.7982255872365629","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@edison-manrique/sha2-wasm","version":"1.1.0","keywords":["wasm","webassembly","sha2","sha256","sha512","hmac","hmac-sha256","hmac-sha512","assemblyscript","crypto"],"author":{"name":"Edison Manrique"},"license":"Apache-2.0","_id":"@edison-manrique/sha2-wasm@1.1.0","maintainers":[{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"}],"homepage":"https://github.com/edison-manrique/sha2-wasm#readme","bugs":{"url":"https://github.com/edison-manrique/sha2-wasm/issues"},"dist":{"shasum":"8670ad61d6097f09f7e9d15431bf6e1eacd0c6f6","tarball":"https://registry.npmjs.org/@edison-manrique/sha2-wasm/-/sha2-wasm-1.1.0.tgz","fileCount":12,"integrity":"sha512-4oirxL5H4LUNiYykB/NBY0CCtMVoRtJEXPcdDsMbi6nEFNk6u6xob6muAmek6uYpjwFxiVNHmEukggMP6a48og==","signatures":[{"sig":"MEQCIDRn2Ev4g0uTcBsHU9BW8/y94grVZm8YVkFFh29h4IyBAiA2nkbSgr9b3UbPd7ka2imfbpW92TPmU8Tb4ABprcmrZw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":82036},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"049fd636f9b61ee998bbc74be56cf72d65e3c6c0","scripts":{"test":"bun test test/index.test.ts","build":"bun run build:as && bun run build:ts","build:as":"asc assembly/index.ts --target release","build:ts":"esbuild src/index.ts --bundle --format=esm --minify --platform=browser --outfile=dist/index.js && tsc --emitDeclarationOnly","examples":"bun examples/server.ts","test:stress":"bun test test/stress.test.ts","build:as:debug":"asc assembly/index.ts --target debug","prepublishOnly":"bun run build"},"_npmUser":{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"},"repository":{"url":"git+ssh://git@github.com/edison-manrique/sha2-wasm.git","type":"git"},"_npmVersion":"11.13.0","description":"Implementación de alto rendimiento de SHA-2 (SHA-256 / SHA-512 / HMAC) en AssemblyScript / WebAssembly con un envoltorio modular en TypeScript sin asignación de memoria (zero-allocation).","directories":{},"_nodeVersion":"22.15.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/sha2-wasm_1.1.0_1785180636695_0.468505973508758","host":"s3://npm-registry-packages-npm-production"}},"1.2.0":{"name":"@edison-manrique/sha2-wasm","version":"1.2.0","description":"Implementación de alto rendimiento de SHA-2 (SHA-256 / SHA-512 / HMAC) en AssemblyScript / WebAssembly con un envoltorio modular en TypeScript sin asignación de memoria (zero-allocation).","author":{"name":"Edison Manrique"},"license":"Apache-2.0","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/index.js","types":"./dist/index.d.ts"}},"scripts":{"build:as":"asc assembly/index.ts --target release","build:as:debug":"asc assembly/index.ts --target debug","build:ts":"esbuild src/index.ts --bundle --format=esm --minify --platform=browser --outfile=dist/index.js && tsc --emitDeclarationOnly","build":"bun run build:as && bun run build:ts","prepublishOnly":"bun run build","test":"bun test test/index.test.ts","test:stress":"bun test test/stress.test.ts","examples":"bun examples/server.ts"},"keywords":["wasm","webassembly","sha2","sha256","sha512","hmac","hmac-sha256","hmac-sha512","assemblyscript","crypto"],"repository":{"type":"git","url":"git+ssh://git@github.com/edison-manrique/sha2-wasm.git"},"bugs":{"url":"https://github.com/edison-manrique/sha2-wasm/issues"},"homepage":"https://github.com/edison-manrique/sha2-wasm#readme","engines":{"node":">=18.0.0"},"gitHead":"7e7adec53d4552e52855db96cba44737ba5aedd7","_id":"@edison-manrique/sha2-wasm@1.2.0","_nodeVersion":"22.15.0","_npmVersion":"11.13.0","dist":{"integrity":"sha512-OxSNPXcKIrcqWCRWKeJ0U7ouwflkrkcEAUa9Vze3LYI03RkI8pq+jI0DPjsKSdmiuFwc/vmtJGDmdb5hGukWyA==","shasum":"bcdd0a8a0de8a480af7242b23bbddfb93fdafef4","tarball":"https://registry.npmjs.org/@edison-manrique/sha2-wasm/-/sha2-wasm-1.2.0.tgz","fileCount":12,"unpackedSize":89223,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCqbfDhIhgF+OWK+CoTbHImp1X9CR8piJOYVxs+S7gY6gIgPmkhCVIu95lbHD+1yPHBaOgeQxCUqut8njlnvANCR4k="}]},"_npmUser":{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"},"directories":{},"maintainers":[{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sha2-wasm_1.2.0_1785210866781_0.41039701737532086"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-27T11:05:05.479Z","modified":"2026-07-28T03:54:27.109Z","1.0.0":"2026-07-27T11:05:05.885Z","1.0.1":"2026-07-27T11:19:05.348Z","1.0.2":"2026-07-27T11:30:56.305Z","1.0.3":"2026-07-27T11:33:38.531Z","1.0.4":"2026-07-27T17:35:46.024Z","1.1.0":"2026-07-27T19:30:36.837Z","1.2.0":"2026-07-28T03:54:26.959Z"},"bugs":{"url":"https://github.com/edison-manrique/sha2-wasm/issues"},"author":{"name":"Edison Manrique"},"license":"Apache-2.0","homepage":"https://github.com/edison-manrique/sha2-wasm#readme","keywords":["wasm","webassembly","sha2","sha256","sha512","hmac","hmac-sha256","hmac-sha512","assemblyscript","crypto"],"repository":{"type":"git","url":"git+ssh://git@github.com/edison-manrique/sha2-wasm.git"},"description":"Implementación de alto rendimiento de SHA-2 (SHA-256 / SHA-512 / HMAC) en AssemblyScript / WebAssembly con un envoltorio modular en TypeScript sin asignación de memoria (zero-allocation).","maintainers":[{"name":"edison-manrique","email":"edison.manrique.chocce@gmail.com"}],"readme":"# 🔐 SHA2 WASM\r\n\r\nBiblioteca criptográfica de hashing ultra-rápida y de alto rendimiento compilada en WebAssembly (WASM) utilizando AssemblyScript y empaquetada con un wrapper TypeScript Zero-Allocation.\r\n\r\nSoporta **SHA-256**, **SHA-512**, **HMAC-SHA256**, **HMAC-SHA512** y **PBKDF2** (derivación de claves, RFC 8018) —con **verificación de HMAC en tiempo constante** (a prueba de _timing attacks_)— con rendimiento extremo (**> 217 MB/s** en compute puro, **~2.2 M hashes/s** en hashes pequeños, **~155 K HMAC-verify/s**, **~765 derivaciones PBKDF2/s**) y **0 % de presión sobre el Garbage Collector (GC)**.\r\n\r\n---\r\n\r\n## 🚀 Características Principales\r\n\r\n- ⚡ **Máximo Rendimiento**: Núcleo de compresión desplegado en WebAssembly con más de **217 MB/s** de throughput en compute puro y **~2.2 millones de hashes por segundo** en mensajes pequeños.\r\n- 🧹 **Zero-Alloc (Cero Alocaciones GC)**: Usa un asignador de memoria _scratchpad_ estático (`WasmAllocator`) reservado en tiempo de compilación — ninguna operación reserva memoria en el heap en runtime.\r\n- 🌐 **Multiplataforma**: Funciona sin modificaciones en Node.js, Bun, Deno y Navegadores Web (Vite, Webpack, etc.).\r\n- 🛡️ **Seguridad Crypto**:\r\n  - Algoritmos estándar **SHA-256 / SHA-512** (FIPS 180-4), **HMAC** (RFC 2104) y **PBKDF2** (RFC 8018).\r\n  - **Verificación HMAC en tiempo constante** (`hmacVerify`): comparación por XOR acumulativo sin _early-exit_, inmune a ataques de timing.\r\n  - Correctitud **validada contra `node:crypto`** (hash, HMAC, HMAC-verify y PBKDF2, incluida la detección de alteración).\r\n  - Detección de colisiones del _ring buffer_ en `reset()` — nunca produce un hash corrupto en silencio.\r\n- 🔑 **Derivación de Claves (PBKDF2)**: PBKDF2-HMAC-SHA256/512 con **precomputación de los estados ipad/opad** (~2× más rápido por iteración que un HMAC naive). Ideal para BIP39, WPA2 y almacenamiento de contraseñas.\r\n- 🔄 **Streaming Real**: Hashing de archivos de cualquier tamaño con `file.stream()` y callback de progreso — memoria plana, sin acumular buffers.\r\n- 📦 **Binario Compacto**: ~13.2 KB de WebAssembly optimizado.\r\n\r\n---\r\n\r\n## 📦 Instalación\r\n\r\n```bash\r\nnpm install @edison-manrique/sha2-wasm\r\n```\r\n\r\nO con Bun / Yarn / pnpm:\r\n\r\n```bash\r\nbun add @edison-manrique/sha2-wasm\r\n```\r\n\r\n---\r\n\r\n## 💻 Guía de Uso\r\n\r\n### 1. Inicializar la biblioteca\r\n\r\n```ts\r\nimport { Sha2Wasm, Sha256, Sha512 } from \"@edison-manrique/sha2-wasm\"\r\n\r\n// Carga automática desde la URL por defecto (navegador / bundler)\r\nawait Sha2Wasm.load()\r\n\r\n// O cargando desde un buffer binario explícito (útil para Node.js / Bun):\r\n// import { readFileSync } from \"node:fs\"\r\n// const wasmBuffer = readFileSync(\"node_modules/@edison-manrique/sha2-wasm/dist/sha2.wasm\")\r\n// await Sha2Wasm.fromBuffer(wasmBuffer)\r\n```\r\n\r\n> La carga se realiza **una sola vez**. Después puedes usar `Sha256` / `Sha512` directamente (usan el singleton global).\r\n\r\n### 2. SHA-256 (Hash One-Shot)\r\n\r\nIdeal para hashear datos completos de una sola vez. Devuelve un digest de **32 bytes**.\r\n\r\n```ts\r\nimport { Sha256 } from \"@edison-manrique/sha2-wasm\"\r\n\r\nconst texto = \"Hola Mundo desde sha2-wasm 👋\"\r\n\r\n// 🔐 Hash SHA-256 (devuelve hexadecimal por defecto)\r\nconst hash = Sha256.hash(texto)\r\nconsole.log(hash)\r\n// → \"c61d9e960e9c88c8baed5e49c59da2f779af1b204bf18b4edce461e2a902762c\"\r\n\r\n// 📦 Hash como bytes crudos (Uint8Array de 32 bytes)\r\nconst bytes = Sha256.hash(texto, \"bytes\") // Uint8Array(32)\r\n\r\n// 🔢 También acepta Uint8Array como entrada\r\nconst fromBytes = Sha256.hash(new Uint8Array([0x68, 0x6f, 0x6c, 0x61]))\r\n```\r\n\r\n### 3. SHA-512 (Hash One-Shot)\r\n\r\nMisma API que SHA-256, pero produce un digest de **64 bytes** (128 caracteres hex).\r\n\r\n```ts\r\nimport { Sha512 } from \"@edison-manrique/sha2-wasm\"\r\n\r\nconst hash512 = Sha512.hash(\"Mensaje importante\")\r\n// → string hexadecimal de 128 caracteres\r\n\r\nconst bytes512 = Sha512.hash(\"Mensaje importante\", \"bytes\") // Uint8Array(64)\r\n```\r\n\r\n### 4. HMAC (Código de Autenticación de Mensajes)\r\n\r\nAutentica un mensaje con una clave secreta conforme a **RFC 2104**.\r\n\r\n```ts\r\nimport { Sha256, Sha512, HMAC } from \"@edison-manrique/sha2-wasm\"\r\n\r\nconst clave = \"mi-clave-secreta-super-segura\"\r\nconst mensaje = \"Mensaje confidencial para firmar\"\r\n\r\n// 🔑 HMAC-SHA256 (API estática)\r\nconst mac = Sha256.hmac(clave, mensaje)\r\n\r\n// 🔑 HMAC-SHA512\r\nconst mac512 = Sha512.hmac(clave, mensaje, \"hex\")\r\n\r\n// 🔄 API orientada a objetos (reutiliza clave y algoritmo en varios mensajes)\r\nconst hmac = new HMAC(clave, \"SHA256\")\r\nconst token1 = hmac.digest(\"mensaje 1\")\r\nconst token2 = hmac.digest(\"mensaje 2\")\r\n\r\n// 🧮 Cálculo estático explícito\r\nconst mac2 = HMAC.compute(\"SHA512\", clave, mensaje, \"bytes\") // Uint8Array(64)\r\n```\r\n\r\n### 5. Verificación de HMAC (Constant-Time)\r\n\r\nVerifica un MAC **en tiempo constante** — la comparación recorre siempre los 32/64 bytes con XOR acumulativo y sin _early-exit_, por lo que **no revela información por timing** (esencial para no exponer la validación a ataques de canal lateral).\r\n\r\n```ts\r\nimport { Sha256, HMAC, hexToBytes } from \"@edison-manrique/sha2-wasm\"\r\n\r\nconst clave = \"mi-clave-secreta\"\r\nconst mensaje = \"mensaje a autenticar\"\r\n\r\n// 🔏 Genera el MAC\r\nconst mac = Sha256.hmac(clave, mensaje) // string hex\r\n\r\n// ✅ Verifica (acepta el MAC como hex o como bytes)\r\nconst valido = Sha256.hmacVerify(clave, mensaje, mac) // true\r\nconst validoBytes = Sha256.hmacVerify(clave, mensaje, hexToBytes(mac)) // true\r\n\r\n// ❌ Un MAC alterado o incorrecto → false (sin filtrar cuántos bytes coincidían)\r\nconst falso = Sha256.hmacVerify(clave, mensaje, \"00\".repeat(32)) // false\r\n\r\n// 🔄 Con la API orientada a objetos\r\nconst hmac = new HMAC(clave, \"SHA256\")\r\nconst ok = hmac.verify(mensaje, mac) // true\r\n```\r\n\r\n> Disponible también en `Sha512.hmacVerify(...)` (MAC de 64 bytes).\r\n\r\n### 6. PBKDF2 (Derivación de Claves)\r\n\r\nDeriva una clave criptográfica a partir de una contraseña con **PBKDF2-HMAC-SHA256/512** (RFC 8018). Usa precomputación de los estados ipad/opad para acelerar las iteraciones.\r\n\r\n```ts\r\nimport { Sha256, Sha512 } from \"@edison-manrique/sha2-wasm\"\r\n\r\nconst password = \"mi-contraseña-super-secreta\"\r\nconst salt = \"salt-aleatorio-único-por-usuario\"\r\n\r\n// 🔑 PBKDF2-HMAC-SHA256 (ej. 2048 iteraciones, clave de 32 bytes)\r\nconst key256 = Sha256.pbkdf2(password, salt, 2048, 32) // string hex\r\nconst key256Bytes = Sha256.pbkdf2(password, salt, 2048, 32, \"bytes\") // Uint8Array(32)\r\n\r\n// 🔑 PBKDF2-HMAC-SHA512 (ej. BIP39: 2048 iteraciones, seed de 64 bytes)\r\nconst seed = Sha512.pbkdf2(password, salt, 2048, 64) // string hex (128 chars)\r\n```\r\n\r\n> 🔐 **Recomendaciones**: usa siempre un **salt aleatorio único** por usuario (≥ 16 bytes) y un número de iteraciones alto (OWASP recomienda 600 000+ para PBKDF2-HMAC-SHA256 en almacenamiento de contraseñas). A más iteraciones, más costo para un atacante por fuerza bruta.\r\n\r\n### 7. Streaming (Hash Incremental)\r\n\r\nPara datos que llegan en fragmentos (chunks de red, trozos de archivo, streams). Procesa el hash **sin acumular todo en memoria**.\r\n\r\n```ts\r\nimport { Sha256 } from \"@edison-manrique/sha2-wasm\"\r\n\r\n// 🔄 Crea un hasher incremental\r\nconst hasher = Sha256.createHasher()\r\n\r\n// Alimenta fragmentos (encadenable)\r\nhasher.update(\"primera parte \").update(\"segunda parte \")\r\nhasher.update(new Uint8Array([0x74, 0x65, 0x72, 0x63, 0x65, 0x72, 0x61]))\r\n\r\n// ✅ Finaliza y obtén el digest\r\nconst hash = hasher.digestHex() // hex (sin branch de formato)\r\n// o\r\nconst bytes = hasher.digestBytes() // Uint8Array\r\nconst hex2 = hasher.digest() // hex por defecto\r\n\r\n// ♻️ Reutiliza el hasher SIN reasignar memoria\r\nhasher.reset()\r\nhasher.update(\"nuevo mensaje\")\r\nconst otro = hasher.digestHex()\r\n```\r\n\r\n> ⚠️ Llamar `update()` después de `digest()` lanza un `Error` explícito (no falla en silencio). Usa `reset()` para reutilizar la instancia.\r\n\r\n### 8. Hashing de Archivos (con Progreso)\r\n\r\nHashea un `Blob` / `File` de **cualquier tamaño** con streaming real y memoria plana.\r\n\r\n```ts\r\nimport { Sha256 } from \"@edison-manrique/sha2-wasm\"\r\n\r\n// 📁 Selecciona un archivo (input type=\"file\")\r\nconst file = document.querySelector<HTMLInputElement>(\"input[type=file]\")!.files![0]\r\n\r\n// 🔄 Hashea con callback de progreso\r\nconst hash = await Sha256.hashFile(file, \"hex\", (processed, total) => {\r\n  const pct = Math.round((processed / total) * 100)\r\n  console.log(`Progreso: ${pct}%`)\r\n})\r\n\r\nconsole.log(\"SHA-256 del archivo:\", hash)\r\n// También disponible: Sha512.hashFile(file, \"bytes\", onProgress)\r\n```\r\n\r\n- **Memoria plana**: usa `file.stream()` y procesa chunk a chunk; no acumula buffers grandes en JS.\r\n- **Solapamiento I/O ↔ compute**: el _read-ahead_ lo gestiona el runtime (navegador / Bun).\r\n\r\n### 9. Formatos de Salida y Utilidades\r\n\r\nTodos los métodos aceptan el formato de salida (`\"hex\"` por defecto o `\"bytes\"`):\r\n\r\n```ts\r\nSha256.hash(data) // → string hex (por defecto)\r\nSha256.hash(data, \"hex\") // → string hex\r\nSha256.hash(data, \"bytes\") // → Uint8Array\r\n```\r\n\r\nUtilidades de conversión incluidas:\r\n\r\n```ts\r\nimport { bytesToHex, hexToBytes, toUint8Array } from \"@edison-manrique/sha2-wasm\"\r\n\r\nconst hex = bytesToHex(new Uint8Array([0xde, 0xad, 0xbe, 0xef])) // \"deadbeef\"\r\nconst bytes = hexToBytes(\"deadbeef\") // Uint8Array(4)\r\nconst buf = toUint8Array(\"texto\") // string → Uint8Array (UTF-8)\r\n```\r\n\r\n---\r\n\r\n## 📊 Benchmarks de Rendimiento\r\n\r\nPruebas ejecutadas en Bun (JavaScriptCore) sobre un procesador x86-64 moderno, en single-thread (mediana de 5 muestras):\r\n\r\n| Algoritmo | Caso                           | Throughput    | Ops/seg           |\r\n| --------- | ------------------------------ | ------------- | ----------------- |\r\n| SHA-256   | Compute puro (RAM, 500 MB)     | **217 MB/s**  | —                 |\r\n| SHA-512   | Compute puro (RAM, 500 MB)     | **314 MB/s**  | —                 |\r\n| SHA-256   | HMAC throughput (RAM, 256 MB)  | **209 MB/s**  | —                 |\r\n| SHA-512   | HMAC throughput (RAM, 256 MB)  | **302 MB/s**  | —                 |\r\n| SHA-256   | HMAC verify (1 KB, const-time) | —             | **~155 K ops/s**  |\r\n| SHA-512   | HMAC verify (1 KB, const-time) | —             | **~180 K ops/s**  |\r\n| SHA-256   | PBKDF2 (2048 it, dkLen 32)     | —             | **~765 deriv/s**  |\r\n| SHA-512   | PBKDF2 (2048 it, dkLen 64)     | —             | **~556 deriv/s**  |\r\n| SHA-256   | Hashes pequeños (55 B)         | ~114 MB/s     | **~2.20 M ops/s** |\r\n| SHA-512   | Hashes pequeños (55 B)         | ~95 MB/s      | **~1.85 M ops/s** |\r\n| SHA-256   | Archivo (streaming)            | **~200 MB/s** | —                 |\r\n| SHA-512   | Archivo (streaming)            | **~300 MB/s** | —                 |\r\n\r\n**Comparativa (single-thread):**\r\n\r\n| Contra                                                 | Resultado                                                    |\r\n| ------------------------------------------------------ | ------------------------------------------------------------ |\r\n| [`hash-wasm`](https://www.npmjs.com/package/hash-wasm) | **+5–7 %** más rápido (SHA-256 **1.05×**, SHA-512 **1.07×**) |\r\n| C nativo (`gcc -O3 -march=native`)                     | **~68 %** del nativo                                         |\r\n\r\n> El ~68 % frente a C nativo es la banda alta esperada para WebAssembly (sin acceso a instrucciones específicas de CPU como `-march=native`). A cambio obtienes **portabilidad total**: el mismo binario de 13.2 KB corre en cualquier navegador, Bun o Node.\r\n\r\n---\r\n\r\n## 🏗️ Arquitectura Zero-Allocation\r\n\r\n- **Scratchpad estático**: las zonas de entrada (`PARAM_IN`), salida (`PARAM_OUT`) y trabajo criptográfico (`CRYPTO_WORK`) se reservan en el _data segment_ del WASM en **tiempo de compilación**.\r\n- **Punteros fijos**: los resultados se devuelven en propiedades primitivas (`lastPtr`, `lastLen`) en lugar de objetos intermedios.\r\n- **Única asignación**: el `Uint8Array` final que se entrega al usuario (inevitable para devolver el hash o la clave derivada).\r\n- **Detección de colisiones**: los hashers verifican el IV del contexto en `reset()` y reasignan memoria si otra operación sobrescribió su región.\r\n- **Comparación constant-time**: `hmac_verify_raw` compara el MAC calculado con el esperado mediante XOR + OR acumulativo de longitud fija (32/64 iteraciones, sin branches dependientes de los datos), evitando fugas por timing.\r\n- **PBKDF2 optimizado**: los estados ipad/opad del HMAC se precomputan **una sola vez por clave** y se reutilizan en cada iteración (copia de estado + 2 compresiones por iteración, en vez de 4), reduciendo ~2× el costo del bucle de iteraciones.\r\n\r\n---\r\n\r\n## 🛠️ Comandos de Desarrollo\r\n\r\n```bash\r\n# Compilar binario WASM (AssemblyScript) + bundle TypeScript (esbuild minificado)\r\nbun run build\r\n\r\n# Compilar solo el binario WASM\r\nbun run build:as         # release → dist/sha2.wasm\r\nbun run build:as:debug   # debug → build/debug.wasm + .wat + sourcemap\r\n\r\n# Verificación de tipos\r\nbun run typecheck\r\n\r\n# Benchmark comparativo (vs hash-wasm) + validación de correctitud\r\n# (hash, HMAC, HMAC-verify y PBKDF2 contra node:crypto, incluida detección de alteración)\r\nbun run bench\r\nbun run bench ./ruta/al/archivo.mp4   # con archivo: + I/O puro + hashFile + diagnóstico\r\n\r\n# Tests\r\nbun test test/\r\n```\r\n\r\n---\r\n\r\n## 📁 Estructura del Proyecto\r\n\r\n```\r\nsha2-wasm/\r\n├── assembly/            # Núcleo en AssemblyScript (→ WebAssembly)\r\n│   ├── index.ts         # Exportaciones WASM (hash, hmac, hmac_verify, pbkdf2, ctx streaming)\r\n│   ├── sha256.ts        # SHA-256 (compress, update, final, hmac, hmac_verify)\r\n│   ├── sha512.ts        # SHA-512\r\n│   ├── pbkdf2.ts        # PBKDF2-HMAC-SHA256/512 (RFC 8018, zero-alloc)\r\n│   ├── constants.ts     # Constantes K e IV\r\n│   ├── common.ts        # Helpers (bswap, Ch, Maj, Sigma, sigma)\r\n│   └── memory.ts        # Scratchpad estático (punteros)\r\n├── src/                 # Wrapper en TypeScript\r\n│   ├── index.ts         # Punto de entrada (re-exports)\r\n│   ├── sha2-wasm.ts     # Cargador + API de bajo nivel\r\n│   ├── allocator.ts     # Alocador del scratchpad (zero-alloc)\r\n│   ├── sha256.ts        # Sha256 + Sha256Hasher (hash, hmac, hmacVerify, pbkdf2)\r\n│   ├── sha512.ts        # Sha512 + Sha512Hasher\r\n│   ├── hmac.ts          # Clase HMAC (digest + verify)\r\n│   └── types.ts         # Tipos, interfaces y utilidades\r\n├── test/                # Benchmarks\r\n│   └── bench.ts         # Bench comparativo (vs hash-wasm) + HMAC + verify + PBKDF2\r\n├── dist/                # Build (generado)\r\n├── asconfig.json        # Configuración de AssemblyScript\r\n├── package.json\r\n├── tsconfig.json\r\n├── LICENSE              # Apache-2.0\r\n└── README.md\r\n```\r\n\r\n---\r\n\r\n## 📜 Licencia\r\n\r\n[Apache License 2.0](./LICENSE) © **Edison Manrique**\r\n\r\n> **Exención de responsabilidad:** este software se proporciona \"tal cual\" (AS IS), sin garantía de ningún tipo. Aunque SHA-256, SHA-512, HMAC y PBKDF2 son algoritmos estándar (FIPS 180-4 / RFC 2104 / RFC 8018), esta implementación no ha sido auditada formalmente y no debe emplearse en aplicaciones de seguridad crítica sin verificación independiente.\r\n","readmeFilename":"README.md"}