# @ensdomains/content-hash

> A simple tool to encode/decode content hash for EIP 1577 compliant ENS Resolvers (fork of pldespaigne/content-hash)

Latest version **3.1.1** (published 2026-06-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ensdomains/content-hash
pnpm add @ensdomains/content-hash
yarn add @ensdomains/content-hash
bun add @ensdomains/content-hash
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2026-06-18 |
| First published | 2020-10-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 2 |
| Unpacked size | 39.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 14 |
| Author | ensdomains |
| Maintainers | makoto_inoue, nickjohnson, jefflau, mdt., leeondamiky, taytems, adraffy, v1rtl |
| Keywords | ethereum, ens, eip-1577, resolver, ipfs, swarm, content-hash, content, hash, contenthash, contentHash |

## Links

- npm: https://www.npmjs.com/package/@ensdomains/content-hash
- Repository: https://github.com/ensdomains/content-hash
- Homepage: https://github.com/ensdomains/content-hash#readme
- Issues: https://github.com/ensdomains/content-hash/issues
- npm.io page: https://npm.io/package/@ensdomains/content-hash

## Dependencies (2)

- [multiformats](https://npm.io/package/multiformats.md) ^13.0.0
- [@multiformats/sha3](https://npm.io/package/@multiformats/sha3.md) ^4.0.0

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 3.1.1 (latest) — 2026-06-18
- 3.1.0-rc.1 (next) — 2024-01-14
- 3.1.0 — 2026-06-18
- 3.1.0-rc.0 — 2023-11-09
- 3.0.0 — 2023-08-11
- 3.0.0-beta.5 — 2023-07-18
- 3.0.0-beta.4 — 2023-07-18
- 3.0.0-beta.3 — 2023-07-18
- 3.0.0-beta.2 — 2023-07-18
- 3.0.0-beta.1 — 2023-07-18
- 3.0.0-beta.0 — 2023-07-18
- 2.5.7 — 2021-09-02
- 2.5.6 — 2021-02-17
- 2.5.5 — 2021-02-16
- 2.5.4 — 2021-02-10
- … 1 more at https://npm.io/package/@ensdomains/content-hash/versions

## README

# content-hash

[![npm package](https://img.shields.io/npm/v/@ensdomains/content-hash.svg)](https://www.npmjs.com/package/@ensdomains/content-hash) ![licence](https://img.shields.io/npm/l/@ensdomains/content-hash.svg)

> This is a simple package made for encoding and decoding content hashes as specified in the [EIP 1577](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1577.md).
> This package will be useful for every [Ethereum](https://www.ethereum.org/) developer wanting to interact with [EIP 1577](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1577.md) compliant [ENS resolvers](http://docs.ens.domains/en/latest/introduction.html).

## 🔠 Supported Codec

- `swarm`
- `ipfs`
- `ipns`
- `onion`
- `onion3`
- `skynet`
- `arweave`
- `adnl`

## 📥 Install

```bash
npm install @ensdomains/content-hash
```

## 🛠 Usage

```javascript
import { decode } from "@ensdomains/content-hash";

const encoded =
  "e3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f";

const content = decode(encoded);
// 'QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4'
```

## 📕 API

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

> ⚠️ All **outputs** are **NOT** prefixed with `0x`

### decode( contentHash ) -> string

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

```javascript
import { decode } from "@ensdomains/content-hash";

const encoded =
  "e3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f";

const content = decode(encoded);
// 'QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4'
```

### encode( codec, value) -> string

This function takes a [supported codec](#-supported-codec) as a **string** and a value as a **string** and returns coresponding content hash as a hex **string**.

```javascript
import { encode } from "@ensdomains/content-hash";

const onion = "zqktlwi4fecvo6ri";

const encoded = encode("onion", onion);
// 'bc037a716b746c776934666563766f367269'
```

### getCodec( contentHash ) -> string

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

```javascript
import { getCodec } from "@ensdomains/content-hash";

const encoded =
  "e40101701b20d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162";

const codec = getCodec(encoded);
// 'swarm'
```

### Helpers

- #### cidV0ToV1Base32( ipfsHash ) -> string

  This function takes an ipfsHash and converts it to a CID v1 encoded in base32.

  ```javascript
  import { cidV0ToV1Base32 } from "@ensdomains/content-hash";

  const ipfs = "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG";

  const cidV1 = cidV0ToV1Base32(ipfs);
  // 'bafybeibj6lixxzqtsb45ysdjnupvqkufgdvzqbnvmhw2kf7cfkesy7r7d4'
  ```

- #### cidForWeb( ipfsHash ) -> string

  This function takes any ipfsHash and converts it to DNS-compatible CID.

  ```javascript
  import { cidForWeb } from "@ensdomains/content-hash";

  const ipfs = "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG";

  const cidV1 = cidForWeb(ipfs);
  // 'bafybeibj6lixxzqtsb45ysdjnupvqkufgdvzqbnvmhw2kf7cfkesy7r7d4'
  ```

## 📝 License

This project is licensed under the **MIT License**, you can find it [here](https://github.com/ensdomains/content-hash/blob/master/LICENSE).

> Note that the dependencies may have a different License

## 👥 Acknowledgements

This repo is forked from the original [content-hash](https://github.com/pldespaigne/content-hash) library, which was written by [pldespaigne](https://github.com/pldespaigne).

---
_Source: https://npm.io/package/@ensdomains/content-hash · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
