Socket
Socket
Sign inDemoInstall

hash-base

Package Overview
Dependencies
5
Maintainers
3
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

hash-base

abstract base class for hash-streams


Version published
Maintainers
3
Weekly downloads
10,153,261
decreased by-6.13%

Weekly downloads

Package description

What is hash-base?

The hash-base package is a Node.js module that provides a base implementation for creating hash functions. It is designed to be extended by other modules to create specific hash function implementations. The package simplifies the process of implementing hash algorithms by handling common tasks such as buffering and streaming data.

What are hash-base's main functionalities?

Streaming data through hash function

This code demonstrates how to extend the HashBase class to create a custom hash function. It involves defining the block size in the constructor, implementing the _update method to update the hash state, and the _digest method to produce the final hash output.

"use strict";
const HashBase = require('hash-base');
class MyHash extends HashBase {
  constructor () {
    super(64); // block size
  }
  _update () {
    // update hash state with this._block
  }
  _digest () {
    // return the final hash
    return Buffer.from([]);
  }
}
const hash = new MyHash();
hash.update('Hello, world!');
console.log(hash.digest('hex'));

Other packages similar to hash-base

Readme

Source

hash-base

NPM Package Build Status Dependency status

js-standard-style

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

Keywords

FAQs

Last updated on 01 May 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc