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

ipfs-merkle-dag-node

v0.1.0

Published

data structures and methods for manipulating IPFS objects

Downloads

5

Readme

ipfs-merkle-dag-node

Create and use IPFS Merkle DAGs!

background

This code was originally based off of vijayee's js-ipfs-merkle-dag module. To contrast, this module offers the following key differences:

  1. Only provides DAG node facilities; no assumptions are made re the existance of a DAG Service.
  2. Node objects are immutable. This makes them much easier to use and reason about, since Merkle DAGs too are immutable.
  3. The API provides only the bare necessities to create DAG nodes. More functionality can be added as needed, but odds are you aren't gonna need it.

example

Let's build a DAG where node2 points to node1, and node3 points to the other two:

var Node = require('ipfs-merkle-dag-node')

// node data can be a string or a Buffer
var node1 = new Node('hello')
console.log('Multihash', node1.multihash)
console.log('Data', node1.data)
console.log('Size', node1.size)
console.log('Links', node1.links)
console.log()

// link to other nodes by a list of Links..
var node2 = new Node('world', [node1.asLink('prev')])
console.log('Multihash', node2.multihash)
console.log('Data', node2.data)
console.log('Size', node2.size)
console.log('Links', node2.links)
console.log()

// ..or link using an object that maps names->Nodes
var node3 = new Node('!!!', { 'prev': node1, 'otherPrev': node2 })
console.log('Multihash', node3.multihash)
console.log('Data', node3.data)
console.log('Size', node3.size)
console.log('Links', node3.links)
console.log()

outputs

Multihash QmTnaGEpw4totXN7rhv2jPMXKfL8s65PhhCKL5pwtJfRxn
Data <Buffer 68 65 6c 6c 6f>
Size 7
Links []

Multihash QmRCETTRRkDQsZqxYgPv8QbCdcxoL8SccXo6YTa8t9UMM3
Data <Buffer 77 6f 72 6c 64>
Size 60
Links [ Link {
    name: 'prev',
    size: 7,
    hash: <Buffer 12 20 50 ee 82 31 ac 5b e6 b6 74 d3 5e 80 6d b2 90 0d d4 04 84 50 d2 9a 85 98 55 9a 9c 0d 08 8c c7 e3> } ]

Multihash Qmd6KYy2Rb2wuTHwUFTKg8QqRd1TqSEeD6GULjJuSCtDCA
Data <Buffer 21 21 21>
Size 169
Links [ Link {
    name: 'prev',
    size: 7,
    hash: <Buffer 12 20 50 ee 82 31 ac 5b e6 b6 74 d3 5e 80 6d b2 90 0d d4 04 84 50 d2 9a 85 98 55 9a 9c 0d 08 8c c7 e3> },
  Link {
    name: 'otherPrev',
    size: 60,
    hash: <Buffer 12 20 2a 6a fd e7 89 56 40 b9 09 8f 82 51 ff b0 59 d1 82 b0 88 87 23 ed 18 2b 11 2c fa 40 ba 29 0f 32> } ]

api

var Node = require('ipfs-merkle-dag-node')

var node = new Node(data, links=[])

Creates a new IPFS Merkle DAG node with data contents and links to other DAG nodes links.

data can be either a string or a Buffer. The former will be converted into the latter.

links can either be a list of Links or an object that maps link names (strings) to nodes (Nodes):

Using a list: var node2 = new Node('foo', [node1.asLink('link-name')]

Using an object: var node2 = new Node('foo', { 'link-name': node1 })

If not provided, links will be considered an empty list.

node

Nodes are immutable, and expose the following properties:

  • data - a Buffer containing the data passed in when the node was created.
  • encoded - a Buffer with the binary protobuffer encoding of the node.
  • hash - a Buffer of the object after it has been SHA2-256 hashed.
  • size - for convenience, the size of the encoded data, in bytes.
  • multihash - for convenience, the base58-encoded string of hash.

node.asLink(name)

Creates a new immutable Link object with name name (a string) that points to the node node.

Links have the following properties:

  • name - the name of the link
  • size - the size of the node the link points to, in bytes
  • hash - a Buffer of the object after it has been SHA2-256 hashed.

Node.fromProtobuf(data)

Creates a new DAG node from the binary protobuffer encoding of a node (encoded, above).

install

With npm, run

npm install ipfs-merkle-dag-node

license

MIT

related

js-ipfs - IPFS implementation in JavaScript