![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@ensdomains/content-hash
Advanced tools
A simple tool to encode/decode content hash for EIP 1577 compliant ENS Resolvers (fork of pldespaigne/content-hash)
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.
swarm
ipfs
ipns
onion
onion3
skynet
arweave
npm install @ensdomains/content-hash
import { decode } from "@ensdomains/content-hash";
const encoded =
"e3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f";
const content = decode(encoded);
// 'QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4'
All hex string inputs can be prefixed with
0x
, but it's not mandatory.
⚠️ All outputs are NOT prefixed with
0x
This function takes a content hash as a hex string and returns the decoded content as a string.
import { decode } from "@ensdomains/content-hash";
const encoded =
"e3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f";
const content = decode(encoded);
// 'QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4'
This function takes a supported codec as a string and a value as a string and returns coresponding content hash as a hex string.
import { encode } from "@ensdomains/content-hash";
const onion = "zqktlwi4fecvo6ri";
const encoded = encode("onion", onion);
// 'bc037a716b746c776934666563766f367269'
This function takes a content hash as a hex string and returns the codec as a hex string.
import { getCodec } from "@ensdomains/content-hash";
const encoded =
"e40101701b20d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162";
const codec = getCodec(encoded);
// 'swarm'
This function takes an ipfsHash and converts it to a CID v1 encoded in base32.
import { cidV0ToV1Base32 } from "@ensdomains/content-hash";
const ipfs = "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG";
const cidV1 = cidV0ToV1Base32(ipfs);
// 'bafybeibj6lixxzqtsb45ysdjnupvqkufgdvzqbnvmhw2kf7cfkesy7r7d4'
This function takes any ipfsHash and converts it to DNS-compatible CID.
import { cidForWeb } from "@ensdomains/content-hash";
const ipfs = "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG";
const cidV1 = cidForWeb(ipfs);
// 'bafybeibj6lixxzqtsb45ysdjnupvqkufgdvzqbnvmhw2kf7cfkesy7r7d4'
This project is licensed under the MIT License, you can find it here.
Note that the dependencies may have a different License
This repo is forked from the original content-hash library, which was written by pldespaigne.
FAQs
A simple tool to encode/decode content hash for EIP 1577 compliant ENS Resolvers (fork of pldespaigne/content-hash)
We found that @ensdomains/content-hash demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.