sha1

A tiny, dependency-light JavaScript function for computing SHA-1 hashes

Library
npm
v1.1.1
107stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
38/100Needs Attention
Development Activity0
Maintenance20
Community60
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
36/100Needs Attention
Architecture30
Code Quality35
Innovation25
Learning Curve55

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) or options.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 sha1 package’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').

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