sha1
A tiny, dependency-light JavaScript function for computing SHA-1 hashes
Repository Health
Technical Analysis
sha1 is a minimal JavaScript implementation of the SHA-1 hashing algorithm, ported from CryptoJS for easy use as a standalone npm package. It exposes a single function that takes a string or Node.js Buffer and returns a SHA-1 digest, with optional output as a hex string, binary string, or byte array. Because it has almost no surface area, it remains a common building block in older codebases and scripts that need a quick, dependency-free hash without pulling in Node’s built-in crypto module or a larger toolkit.
What You Get
- A single
sha1(msg)function that returns a hex-encoded SHA-1 digest by default - Optional output formats via
options.asBytes(byte array) oroptions.asString(binary string) - Support for both plain strings and Node.js Buffer input
- A pure-JavaScript implementation with no native bindings, making it portable across environments
Common Use Cases
- Generating quick non-cryptographic checksums or cache keys in legacy Node.js scripts
- Hashing form input or identifiers where a lightweight, dependency-free hash function is preferred over
crypto - Producing SHA-1 digests in browser-bundled code without polyfilling Node’s crypto module
- Maintaining backward compatibility in older projects that already depend on the
sha1package’s specific API shape
Under The Hood
Architecture - The entire library lives in a single 82-line file, sha1.js, which implements the SHA-1 compression function (message padding, 80-round bitwise mixing, and the five 32-bit state words) directly in JavaScript, ported from the CryptoJS project; the exported sha1(msg, options) function normalizes input (string or Buffer) into UTF-8 bytes via the small charenc and crypt helper dependencies, runs the digest, then formats the result as hex, binary string, or byte array depending on the options flags. Tech Stack - Pure CommonJS JavaScript with no build step and no native bindings; its only runtime dependencies are charenc and crypt (tiny character-encoding helpers from the same CryptoJS-derived family), and its sole devDependency is Mocha for the test suite. Code Quality - A 25-line Mocha test file (test.js) covers a known-answer hash check, a randomness/collision sanity check, and Buffer-input handling, but there is no linting, no CI badge maintained past 2016, and no type definitions; naming is terse (sha1, msg) consistent with the library’s minimal scope. API Design - The API is a single function call with an optional options object, which makes it extremely easy to adopt, but it has been unmaintained since 2016 and offers no built-in incremental/streaming hashing, unlike Node’s native crypto.createHash('sha1').
Used by 3 apps in this directory
APITable
Low Code Platforms · Databases
API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.
anytype-ts
Knowledge Management · Note Taking · Collaboration
A local-first, end-to-end encrypted knowledge OS that lets you build notes, tasks, wikis, and entire apps — with your data stored offline and synced peer-to-peer.
CodeSandbox
Code Editors · Developer Tools
Instantly ready browser-based IDE that runs full npm dependency resolution and transpilation entirely client-side, with no server needed.