# Multihash encode

`multihash-encode` · version 1.0.0 · Hashing & signatures · free, no key needed

Encode a bounded digest as a canonical hexadecimal multihash.

**Use when you need to: encode digest as multihash · build canonical multihash bytes · wrap sha3 digest in multihash.**

## Decide before calling

Read the [versioned contract](/v1/tools/multihash-encode/versions/1.0.0) and the supported scope below. Reuse `multihash-encode@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 `multihash-encode@1.0.0` for encode digest as multihash. 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

- encode digest as multihash
- build canonical multihash bytes
- wrap sha3 digest in multihash
- serialize a sha2 multihash
- create blake3 multihash envelope
- convert digest to multihash hex

## Not supported

- computing a digest from content
- unlisted multicodec algorithms

## Behavior

- Encodes varint(code), varint(digest byte length), then digest bytes.
- Hex input and output are lowercase and varints are minimal.
- Disclaimer: format transform only; provides no confidentiality, integrity, or authenticity.

## Input

- `algorithm` (one of "sha2-256", "sha2-512", "sha3-512", "sha3-384", "sha3-256", "sha3-224", "blake3", "blake2b-256", "blake2b-512", "blake2s-256", required)
- `digest` (string, required): max length 128; pattern `^(?:[0-9a-f]{2})*$`

## Output

- `multihash` (string, required): pattern `^[0-9a-f]+$`
- `code` (integer, required): min 0
- `digest_size` (integer, required): min 0; max 64
- `standard` (string, required)
- `reference` (string, required)
- `data_version` (string, required)

## Limits

- max digest bytes: 64
- max multihash bytes: 68

## Example

Request input:

```json
{
  "algorithm": "sha2-256",
  "digest": "0000000000000000000000000000000000000000000000000000000000000000"
}
```

Response:

```json
{
  "result": {
    "multihash": "12200000000000000000000000000000000000000000000000000000000000000000",
    "code": 18,
    "digest_size": 32,
    "standard": "Multiformats Multihash specification",
    "reference": "multihash = varint(code) || varint(size) || digest; unsigned LEB128 must be minimally encoded",
    "data_version": "multicodec-2026-10-24"
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "multihash-encode",
  "version": "1.0.0",
  "input": {
    "algorithm": "sha2-256",
    "digest": "0000000000000000000000000000000000000000000000000000000000000000"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/multihash-encode/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"algorithm":"sha2-256","digest":"0000000000000000000000000000000000000000000000000000000000000000"}'
```

The machine-readable contract is at [/v1/tools/multihash-encode/versions/1.0.0](/v1/tools/multihash-encode/versions/1.0.0).

### CLI

```sh
node cli.mjs run multihash-encode 1.0.0 --input input.json --base-url https://computefirst.net
```

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

## Related tools

- [Multihash decode](/tools/multihash-decode): Strictly decode a canonical bounded hexadecimal multihash.
- [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.
- [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.
- [Crc catalog compute](/tools/crc-catalog-compute): Compute a pinned RevEng CRC of hex bytes, including crossed-endian CRC-12/UMTS.
- [Multihash digest verify](/tools/multihash-digest-verify): Verify exact digest bytes and optional algorithm against a canonical multihash.
- [Crc check value verify](/tools/crc-check-value-verify): Recompute a pinned catalogue CRC of ASCII 123456789 and compare an observed check.
