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

content-hash

v2.5.2

Published

simple tool to encode/decode content hash for EIP 1577 compliant ENS Resolvers

Downloads

925,544

Readme

content-hash

npm packageCircleCIlicenceGitter chatBeerpay

This is a simple package made for encoding and decoding content hashes as specified in the EIP 1577. This package will be useful for every Ethereum developer wanting to interact with EIP 1577 compliant ENS resolvers.

Here you can find a live demo of this package.

🔠 Supported Codec

  • swarm-ns
  • ipfs-ns
  • ipns-ns
  • Every other codec supported by multicodec will be encoded by default in utf-8.

You can see the full list of codec supported here

📥 Install

  • via npm :
    $> npm install content-hash
  • via Github : Download or clone this repo, then install the dependencies.
    $> git clone https://github.com/pldespaigne/content-hash.git
    $> cd content-hash
    $> npm install

For browser only usage, installation is not required.

🛠 Usage

Import the module in order to use it :

  • NodeJS :
    const contentHash = require('content-hash')
  • Browser :
    <!--From CDN-->
    <script type="text/javascript" src="https://unpkg.com/content-hash/dist/index.js"></script>
    
    <!--From local module-->
    <script type="text/javascript" src="path/to/dist/index.js"></script>

To rebuild the browser version of the package run npm run build into the root folder. Don't forget to also run npm run lint and npm test before building !

📕 API

All hex string inputs can be prefixed with 0x, but it's not mandatory.

⚠️ All outputs are NOT prefixed with 0x

contentHash.decode( contentHash ) -> string

This function takes a content hash as a hex string and returns the decoded content as a string.

const encoded = 'e3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f'

const content = contentHash.decode(encoded)
// 'QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4'

contentHash.fromIpfs( ipfsHash ) -> string

This function takes an IPFS address as a base58 encoded string and returns the encoded content hash as a hex string.

this function just call contentHash.encode() under the hood

const ipfsHash = 'QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4'

const contentH = contentHash.fromIpfs(ipfsHash)
// 'e3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f'

contentHash.fromSwarm( swarmHash ) -> string

This function takes a Swarm address as a hex string and returns the encoded content hash as a hex string.

this function just call contentHash.encode() under the hood

const swarmHash = 'd1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162'

const contentH = contentHash.fromSwarm(swarmHash)
// 'e40101701b20d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162'

contentHash.encode( codec, value) -> string

This function takes a supported codec as a string and a value as a string and returns coresponding content hash as a hex string.

const onion = 'zqktlwi4fecvo6ri'
contentHash.encode('onion', onion);
// 'bc037a716b746c776934666563766f367269'

contentHash.getCodec( contentHash ) -> string

This function takes a content hash as a hex string and returns the codec as a hex string.

const encoded = 'e40101701b20d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162'

const codec = contentHash.getCodec(encoded) // 'swarm-ns'
codec === 'ipfs-ns' // false

contentHash.helpers

This object contain the following helpers functions :

  • cidV0ToV1Base32( ipfsHash ) -> string

    This function takes an ipfsHash and convert it to a CID v1 encoded in base32.
    const ipfs = 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG'
    
    const cidV1 = contentHash.helpers.cidV0ToV1Base32(ipfs)
    // 'bafybeibj6lixxzqtsb45ysdjnupvqkufgdvzqbnvmhw2kf7cfkesy7r7d4'

👨‍💻 Maintainer

🙌 Contributing

For any questions, discussions, bug report, or whatever I will be happy to answer through the issues or on my twitter 😁. PR (with tests) are also welcome !

📝 License

This project is licensed under the ISC License, you can find it here.

Note that the dependencies may have a different License