js-sha256

A fast, zero-dependency SHA-256/SHA-224 hashing library for JavaScript with built-in UTF-8 support and HMAC.

Library
npm
v1.0.0
972stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
68/100Good
Development Activity60
Maintenance52
Community72
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
60/100Good
Architecture75
Code Quality70
Innovation55
Learning Curve40

js-sha256 is a lightweight, zero-dependency implementation of the SHA-256 and SHA-224 hash algorithms for JavaScript, with native UTF-8 string encoding built directly into the hashing loop rather than relying on external encoding utilities. It ships as dual ESM/CommonJS packages with dedicated Node.js, browser, and UMD builds, and automatically delegates to Node’s built-in crypto module when running server-side for maximum performance, while falling back to a hand-optimized pure-JavaScript implementation in browsers and other environments.

Beyond straight hashing, the library bundles HMAC-SHA256/SHA224 support, a chainable create()/update() streaming API for hashing data incrementally, and multiple output formats (hex, byte array, digest, ArrayBuffer) so it can slot into crypto pipelines, checksum tools, or client-side authentication flows without extra glue code.

What You Get

  • Standalone sha256()/sha224() one-shot hashing functions plus HMAC equivalents (sha256.hmac(), sha224.hmac())
  • A streaming create()/update() API for hashing data incrementally across multiple chunks
  • Four output formats from the same hash object: hex(), array()/digest(), and arrayBuffer()
  • Dual ESM/CommonJS builds plus a UMD/minified browser bundle and TypeScript type declarations (index.d.ts)
  • Automatic native crypto delegation on Node.js, with a dependency-free pure-JS fallback for browsers

Common Use Cases

  • Generating file/content checksums client-side before upload, without a server round-trip
  • Computing HMAC-SHA256 signatures for API request authentication in browser-based apps
  • Hashing data in size-constrained frontend bundles where WebCrypto’s async API is awkward to use
  • Cross-environment hashing utilities that need identical output whether running in Node.js or a browser

Under The Hood

Architecture The library is organized around a single core module (src/core.mjs) implementing the Sha256 constructor function as a prototype-based state machine (block-buffering, update/hash/finalize lifecycle), wrapped by lightweight factory functions (createMethod, createHmacMethod) that produce the public sha256/sha224 API surface exposing one-shot, streaming, and HMAC variants. src/index.mjs re-exports from core.mjs for the default ESM entry, while src/node.mjs is a parallel, structurally distinct implementation (a NodeHasher class wrapping Node’s crypto.createHash/createHmac) selected via package.json’s exports “node” condition; src/cjs.mjs, node-cjs.mjs, and umd.mjs are thin build-time wrappers bundled by rollup.config.mjs into build/. The notable design decision is two parallel hashing engines — pure-JS and native crypto — rather than one shared abstraction, so a change to the compression loop in core.mjs has no effect on Node’s runtime behavior since node.mjs is an entirely separate code path.

Tech Stack The package has zero runtime dependencies; devDependencies are limited to @playwright/test, @rollup/plugin-terser, c8 for coverage, mocha, and rollup for bundling. rollup.config.mjs produces multiple bundle targets (ESM, CJS, Node CJS, minified UMD) matching the package.json exports map, targeting both Node.js (via native crypto) and browsers (via the UMD/ESM bundle). TypeScript types are shipped as a hand-written static index.d.ts rather than compiled from TypeScript source. The CI pipeline (.github/workflows/ci.yml) packs the npm artifact on Node 24 and then re-runs the runtime test suite against that artifact across Node 16 through 24 to validate cross-version compatibility.

Code Quality Tests are organized with mocha (tests/core-test.mjs, tests/node-test.mjs, tests/hmac-test.js, tests/test.js) plus a dist-test.mjs that validates the built artifacts, and Playwright covers browser-specific behavior (tests/browser, playwright.config.mjs, including classic and module Web Worker scenarios). c8 collects coverage scoped explicitly to the core source files. Error handling is minimal but deliberate: formatMessage throws on an invalid input type, and update()/finalize() throw a FINALIZE_ERROR once a hash has already been finalized, guarding against accidental reuse. There is no TypeScript source to type-check against the hand-written declaration file, and no linter or formatter configuration is present in the repo, though the multi-version Node CI and separate node/browser/dist suites give reasonable confidence for a library of this scope.

What Makes It Unique Rather than a novel algorithm, js-sha256’s differentiator is a hand-inlined, loop-unrolled SHA-256 compression function (visible in Sha256.prototype.hash, unrolled in groups of four rounds with manually tracked rotate/majority/choice terms and a special-cased first round to skip redundant reads) tuned for raw JS engine speed without WASM or native bindings, combined with automatic dual-mode dispatch to Node’s native crypto module when available. That combination gives consistent hash output across environments while getting near-native performance server-side and reasonable performance in pure JavaScript client-side — a solid but incremental performance-engineering choice rather than a groundbreaking one; comparable unrolling techniques appear in several other JS hash libraries.

Used by 11 apps in this directory

Go
60%
Apache 2.0

Apache Answer

Community

15,665

Open-source Q&A platform for communities, help centers, and knowledge bases with AI assistant and plugin extensibility

View details
83
Repo Health
78
Technical
68
Dependency
Built with
Go60%
TypeScript36%
Updated 1 weeks ago
TypeScript
68%
Apache 2.0

Appsmith

Developer Tools · Automation · No Code Platforms

40,825

Open-source low-code platform to build admin panels, dashboards, and internal tools connected to any database or API.

View details
93
Repo Health
79
Technical
66
Dependency
Built with
TypeScript68%
Java21%
Updated 3 days ago
Python
68%
Other

Baserow

No Code Platforms · Databases

5,830

Open-source no-code platform to build databases, apps, automations, and AI agents — self-hosted or cloud, with full data ownership.

View details
89
Repo Health
84
Technical
68
Dependency
Built with
Python68%
JavaScript16%
Vue12%
Updated yesterday
TypeScript
99%
Apache 2.0

Colanode

Knowledge Management · Team Chat · Collaboration

5,097

Local-first, self-hosted workspace that combines real-time chat, Notion-style pages, and structured databases — all synced via CRDTs so you work offline without losing a keystroke.

View details
47
Repo Health
73
Technical
70
Dependency
Built with
TypeScript99%
Updated 5 months ago
TypeScript
45%
Other

Convex Backend

Developer Tools · Databases

12,494

Open-source reactive database that lets developers build live-updating apps with pure TypeScript, strong consistency, and real-time subscriptions—no separate API layer required.

View details
87
Repo Health
82
Technical
68
Dependency
Built with
TypeScript45%
Rust43%
Updated 2 days ago
TypeScript
100%
Other

Dub

Marketing · Analytics

24,676

The open-source link attribution platform for short links, conversion tracking, and affiliate programs — powering 100M+ clicks monthly.

View details
80
Repo Health
78
Technical
62
Dependency
Built with
TypeScript100%
Updated 2 days ago
TypeScript
99%
Other

LobeHub

AI Assistants · Productivity · Automation

82,273

Your Chief Agent Operator — build, schedule, and collaborate with an entire AI team in one self-hostable workspace.

View details
92
Repo Health
81
Technical
69
Dependency
Built with
TypeScript99%
Updated today
Python
37%
Other

Open WebUI

AI Assistants · AI Agents

151,143

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
91
Repo Health
75
Technical
66
Dependency
Built with
Python37%
Svelte34%
JavaScript21%
Updated yesterday
PHP
63%
Other

OpnForm

Forms Surveys · Marketing

3,678

Build unlimited, embeddable forms with no code — powered by AI, logic rules, and real-time analytics

View details
90
Repo Health
75
Technical
68
Dependency
Built with
PHP63%
Vue29%
Updated 3 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search