npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hash-chain

v2.0.1

Published

Hash Chain implementation using Blake2b

Downloads

114

Readme

hash-chain

Hash Chain implementation using Blake2b

Usage

var HashChain = require('hash-chain')

Persistence:

var chain = // ...
const fs = require('fs')
const fd = fs.open('filename')
fs.write(fd, chain.offset, 0, 4)
fs.write(fd, chain.chain)
fs.close(fd)
const fs = require('fs')
const data = fs.readFile('filename')

var chain = new HashChain(data.subarray(4), data.readUInt32LE(0))

API

const seed = HashChain.seedgen([buf])

Generate a new seed, optionally into an existing Buffer buf.

const ch = HashChain.generate(seed, n, [offset = 0])

Generate and instantiate a new HashChain from seed Buffer with n elements.seed must be HashChain.SEEDBYTES long. Optionally offset the chain.

const ch = HashChain.fromAnchors(anchors, dist, [offset = 0])

Generate and instantiate a new lazy HashChain a list of anchor points, with dist elements between each anchor. Optionally offset the chain. This will only keep a buffer of dist points in memory, lazily generating missing points as they're accessed.

const ch = new HashChain(chainBuf, baseOffset = 0)

Instantiate a new HashChain from an existing chainBuf at offset.

const chainBuf = ch.chain

Read the Buffer used in the chain ch

const offset = ch.offset

Read the current integer offset

const len = ch.length

Total number of elements in the chain

const elm = ch.get(offset)

Get the element as a Buffer at offset from the offset given in the constructor. Normally HashChains only move forward, but giving a negative integer allows you to go back. This does not increment the internal counter.

for (const elm of ch) (Symbol.iterator)

Iterate over the elements in the chain using an Iterator

const anchors = ch.anchors(dist)

Generate anchor points with dist elements between each anchor. This can be used to optimise initialisation of an existing chain at the expense of more disk space.

Install

npm install hash-chain

License

ISC