Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

hash-base

crypto-browserify70.5mMIT3.1.2

abstract base class for hash-streams

hash, stream

readme

hash-base

npm Package Build Status Dependency status

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

Example

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 or crypto-browserify/md5.js

LICENSE

MIT

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v3.1.2 - 2025-09-22

Commits

  • [fix] package already works in node 0.8 1c19201
  • [Dev Deps] add missing peer dep 7ac34b6

v3.1.1 - 2025-09-22

Commits

  • [eslint] switch to eslint d63bf3b
  • [meta] add auto-changelog b2c7408
  • [Tests] avoid tape-mutating beforeEach nonsense bb1f9b6
  • [Tests] avoid tape-mutating beforeEach nonsense ae228cd
  • [readme] clean up formatting fd5cb3d
  • [readme] clean up formatting a13ed61
  • [Tests] migrate from travis to GHA 9e2c04c
  • [Tests] migrate from travis to GHA 31766d4
  • [Fix] return valid values on multi-byte-wide TypedArray input 1af18ee
  • [Refactor] use to-buffer 41d738b
  • [Dev Deps] update tape, downgrade nyc, clean up scripts 13d373c
  • [Dev Deps] update tape, downgrade nyc, clean up scripts 84f4fab
  • [meta] use npmignore ecdd9a3
  • Merge tag 'v3.0.5' d59c766
  • Only apps should have lockfiles de3ce83
  • Only apps should have lockfiles 05b7504
  • [Deps] update inherits, safe-buffer 2b8687d
  • [Deps] update safe-buffer; downgrade readable-stream 523da5d
  • [Tests] clean up linting 4274b7c
  • [Tests] in node 0.10, Buffer .fill returns undefined 0fdfd67
  • [Tests] in node 0.10, Buffer .fill returns undefined 5d1f911
  • [Fix] restore engines.node from 3.0.0 8cbfd12
  • [Fix] restore engines.node from 3.0.0 b99d8a1
  • [Tests] use safe-buffer in tests, too 84bdfe9
  • [Tests] use safe-buffer in tests, too 9182f82

v3.1.0 - 2020-05-01

Merged

  • Update deps, add readable-stream #14

v3.0.5 - 2024-11-23

Commits

  • [Tests] avoid tape-mutating beforeEach nonsense ae228cd
  • [readme] clean up formatting a13ed61
  • [Tests] migrate from travis to GHA 31766d4
  • [Fix] return valid values on multi-byte-wide TypedArray input 1af18ee
  • [Dev Deps] update tape, downgrade nyc, clean up scripts 13d373c
  • Only apps should have lockfiles de3ce83
  • [Deps] update inherits, safe-buffer 2b8687d
  • [Tests] clean up linting 4274b7c
  • [Tests] in node 0.10, Buffer .fill returns undefined 5d1f911
  • [Fix] restore engines.node from 3.0.0 8cbfd12
  • [Tests] use safe-buffer in tests, too 9182f82

v3.0.4 - 2017-05-24

Merged

  • use safe-buffer #12
  • Only Node v4 or greater [Buffer only] #11
  • Reset state after #_digest #10

Commits

v3.0.3 - 2016-08-28

Commits

v3.0.2 - 2016-08-25

Commits

v3.0.1 - 2016-08-09

Merged

  • Fix ._flush #7
  • Update nyc to version 7.0.0 🚀 #6

Commits

  • Change .digest to .digest in .flush fdad9ad
  • Fix typo in README.md 13264ec
  • chore(package): update nyc to version 7.0.0 2a24e6a

v3.0.0 - 2016-05-04

Merged

  • utf8 as default encoding #4
  • Update standard to version 7.0.0 🚀 #5

Commits

  • chore(package): update standard to version 7.0.0 0720515

v2.0.2 - 2016-04-17

Commits

  • Add type checking in .update 96acf4a
  • Normalize encoding in tests (utf-8 to utf8) 0bb7c88

v2.0.1 - 2016-04-14

Commits

  • Use this._block as local variable aa8bab9
  • Change Math.floor to |0 24f7bb5

v2.0.0 - 2016-04-07

Fixed

  • (Closes #3) remove DEFAULT_ENCODING #3

Commits

  • Add blocks handling 0c8fb67
  • (#1) rename _initialized to _finalized ea3c00f
  • Fix code style 964daa5
  • Rename initialised_ to _initialised 6e458c6

v1.0.2 - 2016-04-04

Commits

  • Update should return hash instance 59fef2b

v1.0.1 - 2016-04-04

Commits

v1.0.0 - 2016-04-03

Commits