# hash-base

> abstract base class for hash-streams

Latest version **3.1.2** (published 2025-09-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install hash-base
pnpm add hash-base
yarn add hash-base
bun add hash-base
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 3.1.2 |
| Published | 2025-09-23 |
| First published | 2016-04-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.8 |
| Dependencies | 4 |
| Unpacked size | 18.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Kirill Fomichev |
| Maintainers | ljharb, dcousens, cwmma, fanatid |
| Keywords | hash, stream |

## Links

- npm: https://www.npmjs.com/package/hash-base
- Repository: https://github.com/crypto-browserify/hash-base
- Issues: https://github.com/crypto-browserify/hash-base/issues
- npm.io page: https://npm.io/package/hash-base

## Dependencies (4)

- [inherits](https://npm.io/package/inherits.md) ^2.0.4
- [to-buffer](https://npm.io/package/to-buffer.md) ^1.2.1
- [safe-buffer](https://npm.io/package/safe-buffer.md) ^5.2.1
- [readable-stream](https://npm.io/package/readable-stream.md) ^2.3.8

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 3.1.2 (latest) — 2025-09-23
- 3.0.5 (3.0-latest) — 2024-11-24
- 3.1.1 — 2025-09-22
- 3.1.0 — 2020-05-01
- 3.0.4 — 2017-05-24
- 3.0.3 — 2016-08-28
- 3.0.2 — 2016-08-25
- 3.0.1 — 2016-08-09
- 3.0.0 — 2016-05-04
- 2.0.2 — 2016-04-17
- 2.0.1 — 2016-04-14
- 2.0.0 — 2016-04-07
- 1.0.2 — 2016-04-04
- 1.0.1 — 2016-04-04
- 1.0.0 — 2016-04-03

## README

# hash-base

[![npm Package](https://img.shields.io/npm/v/hash-base.svg?style=flat-square)](https://www.npmjs.org/package/hash-base)
[![Build Status](https://img.shields.io/travis/crypto-browserify/hash-base.svg?branch=master&style=flat-square)](https://travis-ci.org/crypto-browserify/hash-base)
[![Dependency status](https://img.shields.io/david/crypto-browserify/hash-base.svg?style=flat-square)](https://david-dm.org/crypto-browserify/hash-base#info=dependencies)

Abstract base class to inherit from if you want to create streams implementing the same API as node crypto [Hash][1] (for [Cipher][2] / [Decipher][3] check [crypto-browserify/cipher-base][4]).

## Example

```js
const HashBase = require('hash-base');
const inherits = require('inherits');

// our hash function is XOR sum of all bytes
function MyHash () {
	HashBase.call(this, 1); // in bytes

	this._sum = 0x00;
};

inherits(MyHash, HashBase)

MyHash.prototype._update = function () {
	for (let i = 0; i < this._block.length; ++i) {
		this._sum ^= this._block[i];
	}
};

MyHash.prototype._digest = function () {
	return this._sum;
};

const data = Buffer.from([0x00, 0x42, 0x01]);
const hash = new MyHash().update(data).digest();
console.log(hash); // => 67
```
You also can check [source code](index.js) or [crypto-browserify/md5.js][5]

## LICENSE

MIT

[1]: https://nodejs.org/api/crypto.html#crypto_class_hash
[2]: https://nodejs.org/api/crypto.html#crypto_class_cipher
[3]: https://nodejs.org/api/crypto.html#crypto_class_decipher
[4]: https://github.com/crypto-browserify/cipher-base
[5]: https://github.com/crypto-browserify/md5.js

---
_Source: https://npm.io/package/hash-base · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
