# Ipfs cid compute

`ipfs-cid-compute` · version 1.0.0 · Hashing & signatures · free, no key needed

Compute the CIDv0, CIDv1 dag-pb and CIDv1 raw content identifiers 'ipfs add' would give a single-chunk file.

**Use when you need to: what cid would ipfs give this file · compute qm hash for ipfs · cidv1 for this content.**

## Decide before calling

Read the [versioned contract](/v1/tools/ipfs-cid-compute/versions/1.0.0) and the supported scope below. Reuse `ipfs-cid-compute@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `ipfs-cid-compute@1.0.0` for what cid would ipfs give this file. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- what cid would ipfs give this file
- compute qm hash for ipfs
- cidv1 for this content
- ipfs content address without running a node
- bafybe hash for this file
- predict the cid before pinning to ipfs

## Not supported

- multi-chunk / multi-link dag-pb trees (this tool always represents content as one UnixFS chunk, kubo's default for anything at or under its size cap)
- pinning, adding or fetching content from an actual IPFS node

## Behavior

- This tool always represents content as ONE UnixFS chunk (a single dag-pb node with no Links), exactly what kubo's default 256 KiB chunker produces for any input at or under this tool's max_content_bytes cap.
- cid_v1_raw: multihash = 0x12 0x20 || SHA-256(content) (content hashed directly, no UnixFS/dag-pb wrapper); CID = multibase('b') || varint(1) || varint(0x55 'raw') || multihash, base32-encoded (lowercase, unpadded).
- The UnixFS node bytes are: field 1 (Type=File) always present; field 2 (Data) present only when content is non-empty (an empty file omits the Data field entirely); field 3 (filesize) always present. The dag-pb node bytes are just field 1 (Data) = these UnixFS bytes, with no Links field.
- cid_v0_dag_pb: multihash = 0x12 0x20 || SHA-256(dag-pb node bytes); CID = base58btc(multihash) with no multibase prefix character and no version/codec varints.
- cid_v1_dag_pb: the same dag-pb node bytes and multihash as cid_v0_dag_pb, but wrapped as CIDv1 with codec 0x70 'dag-pb', base32-encoded.
- size is the decoded byte length of content.

## Input

- `content` (string, required): max length 262144
- `content_encoding` (one of "utf8", "hex", "base64", "base64url", optional): default `"utf8"`

## Output

- `cid_v1_raw` (string, required): pattern `^b[a-z2-7]+$`
- `cid_v0_dag_pb` (string, required): pattern `^Qm[1-9A-HJ-NP-Za-km-z]+$`
- `cid_v1_dag_pb` (string, required): pattern `^b[a-z2-7]+$`
- `size` (integer, required): min 0

## Limits

- max content bytes: 262144

## Example

Request input:

```json
{
  "content": ""
}
```

Response:

```json
{
  "result": {
    "cid_v1_raw": "bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku",
    "cid_v0_dag_pb": "QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH",
    "cid_v1_dag_pb": "bafybeif7ztnhq65lumvvtr4ekcwd2ifwgm3awq4zfr3srh462rwyinlb4y",
    "size": 0
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "ipfs-cid-compute",
  "version": "1.0.0",
  "input": {
    "content": ""
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/ipfs-cid-compute/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"content":""}'
```

The machine-readable contract is at [/v1/tools/ipfs-cid-compute/versions/1.0.0](/v1/tools/ipfs-cid-compute/versions/1.0.0).

### CLI

```sh
node cli.mjs run ipfs-cid-compute 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Git object id compute](/tools/git-object-id-compute): Compute the Git object id git itself would give a blob, tree, commit or tag under Git's exact object framing.
- [Hash digest compute](/tools/hash-digest-compute): Compute a message digest (SHA-2, SHA-3, BLAKE2/3, MD5, RIPEMD-160, Keccak-256) over encoded input bytes.
- [Crc parametric compute](/tools/crc-parametric-compute): Compute a CRC using a named catalogue preset (CRC-8, CRC-16/ARC, CRC-32/ISO-HDLC, ...) or an explicit Rocksoft model.
- [Hash digest verify](/tools/hash-digest-verify): Recompute a fixed-length digest over encoded input bytes and compare it to an expected digest given in any encoding.
- [Sri integrity compute](/tools/sri-integrity-compute): Render one or more digests of content as a W3C Subresource Integrity 'integrity' attribute value.
- [Hash noncrypto compute](/tools/hash-noncrypto-compute): Compute FNV-1/1a, MurmurHash3 or xxHash over encoded input bytes, with an optional seed for algorithms that take one.
