ripemd160-js
v4.0.0
Published
A tiny, zero-dependency RIPEMD-160 implementation for JavaScript and TypeScript.
Maintainers
Readme
ripemd160-js
A tiny, dependency-free, isomorphic RIPEMD-160 implementation for modern JavaScript and TypeScript.
Designed as a minimal cryptographic primitive:
- ≈2 KB package footprint (gzip & minify)
- Zero runtime dependencies
- Native ESM
- Node.js and browser compatible
- TypeScript declarations included
Uint8Arrayin,Uint8Arrayout- No Node.js
Bufferdependency - No WebAssembly runtime required
- No platform-specific crypto APIs
The package operates directly on bytes, making it suitable for cryptographic, blockchain, protocol, encoding, and binary-data applications where RIPEMD-160 compatibility is required.
Installation
npm install ripemd160-jsUsage
import { ripemd160 } from "ripemd160-js";
const input = new Uint8Array([1, 2, 3]);
const digest = ripemd160(input);
console.log(digest);
// Uint8Array(20)ripemd160() is synchronous and always returns a 20-byte Uint8Array.
Hashing text
RIPEMD-160 operates on bytes rather than strings.
Use TextEncoder when hashing UTF-8 text:
import { ripemd160 } from "ripemd160-js";
const input = new TextEncoder().encode(
"the quick brown fox jumps over the lazy dog",
);
const digest = ripemd160(input);This keeps text encoding explicit and avoids ambiguity between UTF-8, UTF-16, Latin-1, or other encodings.
Converting the digest to hex
The library intentionally returns raw bytes rather than imposing an output encoding.
const hex = Array.from(digest, (byte) =>
byte.toString(16).padStart(2, "0"),
).join("");
console.log(hex);For:
the quick brown fox jumps over the lazy dogthe RIPEMD-160 digest is:
704f5bd0a04f44c1f8e5aced93c381db13f1af5bTypeScript
TypeScript declarations are included with the package.
import { ripemd160 } from "ripemd160-js";
const input: Uint8Array = new TextEncoder().encode("hello");
const digest: Uint8Array = ripemd160(input);The API is deliberately small:
function ripemd160(input: Uint8Array): Uint8Array;No additional types, classes, contexts, or platform abstractions are required.
Browser
ripemd160-js uses standard JavaScript typed arrays and can be imported directly into modern browser applications:
import { ripemd160 } from "ripemd160-js";
const data = new TextEncoder().encode("hello");
const digest = ripemd160(data);There are no Node.js-specific runtime dependencies such as:
Buffer
crypto
stream
processand no polyfills are required by the RIPEMD-160 implementation itself.
Node.js
The same API works natively in Node.js:
import { ripemd160 } from "ripemd160-js";
const data = new TextEncoder().encode("hello");
const digest = ripemd160(data);The package uses native ECMAScript modules:
import { ripemd160 } from "ripemd160-js";CommonJS require() is intentionally not provided.
Why Uint8Array?
Cryptographic hash functions operate on bytes.
Earlier versions of ripemd160-js provided additional conversion behavior for strings and encoded output. The current API reduces the library to the underlying primitive:
Uint8Array → RIPEMD-160 → Uint8Array(20)This has several advantages:
- explicit input encoding
- predictable output
- smaller implementation
- simpler TypeScript types
- fewer platform-specific assumptions
- easier interoperability with binary protocols
- no implicit string conversion
- no dependency on Node.js
Buffer
For text:
new TextEncoder().encode("hello");For hex or other output formats, encode the returned digest according to the requirements of your application.
Minimal by design
ripemd160-js intentionally does one thing:
RIPEMD-160Isomorphic
The implementation is based entirely on standard ECMAScript primitives including:
Uint8Array
Int32Array
Array
Math
32-bit bitwise operationsAs a result, the RIPEMD-160 implementation itself is environment-independent and suitable for environments that support standard JavaScript typed arrays.
API
ripemd160(input)
Calculates the RIPEMD-160 digest of a byte sequence.
Parameters
input: Uint8Array;The bytes to hash.
Returns
Uint8Array;A 20-byte RIPEMD-160 digest.
Example
import { ripemd160 } from "ripemd160-js";
const digest = ripemd160(new Uint8Array([1, 2, 3, 4]));Development
Install development dependencies:
npm installBuild the TypeScript source:
npm run buildRun the test suite:
npm testFormat the project:
npm run prettier:fixCheck the contents that would be published to npm:
npm pack --dry-runThe TypeScript source lives under:
src/and is compiled into:
dist/Only the compiled distribution is included in the published npm package.
Compatibility
ripemd160-js is intended for:
- Node.js
- browsers
- TypeScript
- JavaScript
- bundlers
- server-side runtimes
- client-side applications
- blockchain and protocol tooling
The distributed JavaScript uses native ECMAScript modules.
RIPEMD-160 security note
RIPEMD-160 is an older cryptographic hash function.
This package exists primarily for compatibility with protocols and systems that specifically require RIPEMD-160, including various blockchain and cryptographic formats.
For new protocols where no compatibility requirement exists, prefer a modern cryptographic hash function appropriate to the security requirements of the application.
License
MIT
