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

hashgraph

v0.0.5

Published

This is a hashgraph implementation written in javascript. It is currently in development and not yet ready to be used.

Downloads

20

Readme

Hashgraph

This javascript implementation is not working. Please check out the implementation in Golang instead: Click here.

This is a hashgraph implementation written in javascript. It uses IPFS as storage and networking backend. It is currently in development and not yet ready to be used. The functionality described below does not work yet.

The goal of this project is a hashgraph implementation that can be used in any javascript project that is run on several nodes that require a consensus order (globally agreed-upon timestamps) of occured events. The most general use cases are any kinds of distributed state machines.

Specification

For a formal specification of the hashgraph and the hashgraph consensus, please refer to the white paper. The following specification just maps the abstract idea described in the whitepaper to an existing implementation.

The specification is lifted from an experimental implementation in python which seemed workable to me. A hashgraph event is stored as a node of the merkel DAG in the IPFS network.

The Data of the node is a JSON string with the following format:

Data: {"c": "event peerID", "t": unix time of event (in seconds, floating point), "d": "event payload"}

The Links of the node point to the parents of the event.

Links: [{"Name": "0", "Hash": ownParentHash}, {"Name": "1", "Hash": otherParentHash}]

Tests

Currently this code does not use a real testing framework.

The following script sets up multiple hashgraph repositories in ~/.hashgraph_test_X and runs multiple nodes to test the consensus mechanism. Be sure to run a local IPFS daemon while running the tests.

coffee tests/test_hashgraph.coffee

You can safely delete the repositories if you're not using them anymore.

Getting Started

Installation

The javascript implementation of IPFS is not yet fully featured (IPNS is missing). For now, this project depends on the go-lang implementation to be installed. If you're using Ubuntu, you can use this script to install it:

curl https://raw.githubusercontent.com/buhrmi/hashgraph/master/install.sh | sh

Then install NPM and the hashgraph package:

npm install hashgraph --save
    

Usage

In your node application, you can create a new hashgraph node like so:

hashgraph = require('hashgraph')(options)
hashgraph.init()

Supported options are:

  • path: The path to the hashgraph repository. This is an IPFS repository that stores your private key pair and a local copy of the hashgraph data. Default: ~/.hashgraph

You can access information about your own hashgraph peer:

hashgraph.on('ready', function() {
  console.log(hashgraph.info())
})

The info() method returns an object with the following properties:

  • peerID: Your own peer ID.
  • head: The Hash of the last event recorded by your peer.

It's a little bit boring to run the network only with one node. You can join another peer like so:

hashgraph.join(remotePeerID)

After joining another node on the network you can submit transactions to the network like this:

hashgraph.on('ready', function() {
  hashgraph.sendTransaction('somePayload');
})

After the transaction has been sent to the network, it will try to achieve consensus over the question where to place this transaction in the global order of all transactions in the network. Once consensus has been achieved, the hashgraph will emit an event that you can listen to:

hashgraph.on('consensus', function(transactions) {
  // Apply transactions to state machine
  // The transactions in the `transactions` parameter are now covered by the consensus.
  // The order of the transactions is guaranteed to be the same among all participating nodes.
})

This is all you need to know to use hashgraph with your own projects. Read on for information on how to use the hashgraph ledger.