# Bech32 decode

`bech32-decode` · version 1.0.0 · Encoding & checksums · free, no key needed

Decode Bech32 or Bech32m text into a lowercase HRP, 5-bit data, and the checksum variant.

**Use when you need to: decode bech32 or bech32m text into hrp and symbols · tell bech32 apart from bech32m by checksum · lowercase a bech32 string after checking its checksum.**

## Decide before calling

Read the [versioned contract](/v1/tools/bech32-decode/versions/1.0.0) and the supported scope below. Reuse `bech32-decode@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 `bech32-decode@1.0.0` for decode bech32 or bech32m text into hrp and symbols. 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

- decode bech32 or bech32m text into hrp and symbols
- tell bech32 apart from bech32m by checksum
- lowercase a bech32 string after checking its checksum
- read five-bit data from a bech32 string
- reject mixed case bech32 text
- parse a bech32m checksummed string
- split bech32 text on the final separator
- recover the hrp from an uppercase bech32 string

## Not supported

- create a new bech32 checksum
- convert 8-bit bytes to 5-bit symbols
- enforce segwit program length or witness version
- locate which character was mistyped

## Behavior

- Accepts a single-case string of at most 90 characters. All-uppercase and all-lowercase are both accepted. Mixed ASCII case is rejected before the checksum, then the string is returned in lowercase.
- The separator is the last character 1. The HRP before it must be 1 to 83 characters of ASCII 33-126. The body must be charset characters qpzry9x8gf2tvdw0s3jn54khce6mua7l with at least 6 checksum characters.
- The checksum selects the variant. Polymod residue 1 is bech32 (BIP 173). Polymod residue 0x2bc830a3 is bech32m (BIP 350). Any other residue is a bad checksum. data omits those 6 symbols.
- Format failures throw invalid_input. A string longer than 90 characters throws limit_exceeded before charset or checksum work. No witness-version policy is applied.
- Disclaimer: format transform only; provides no confidentiality, integrity, or authenticity.

## Input

- `text` (string, required): min length 8; max length 90; pattern `^[\x21-\x7e]+$`

## Output

- `hrp` (string, required): min length 1; max length 83; pattern `^[\x21-\x40\x5b-\x7e]+$`
- `data` (array of integer, required): max items 82; each min 0; each max 31
- `variant` (one of "bech32", "bech32m", required)
- `text` (string, required): min length 8; max length 90; pattern `^[\x21-\x40\x5b-\x7e]+$`

## Limits

- max text chars: 90

## Example

Request input:

```json
{
  "text": "A12UEL5L"
}
```

Response:

```json
{
  "result": {
    "hrp": "a",
    "data": [],
    "variant": "bech32",
    "text": "a12uel5l"
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "bech32-decode",
  "version": "1.0.0",
  "input": {
    "text": "A12UEL5L"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/bech32-decode/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"text":"A12UEL5L"}'
```

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

### CLI

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

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

## Related tools

- [Bech32 validate](/tools/bech32-validate): Check Bech32 or Bech32m text and return a reason, without throwing when the checksum fails.
- [Bech32 encode](/tools/bech32-encode): Encode lowercase HRP and 5-bit data as Bech32 or Bech32m text using that checksum.
- [Bech32 convert bits](/tools/bech32-convert-bits): Regroup integers between bit widths using BIP 173 rules, rejecting bad leftover padding.
- [Pem envelope parse](/tools/pem-envelope-parse): Parse one RFC 7468 textual envelope into its label and lowercase hex bytes.
- [Segwit address decode](/tools/segwit-address-decode): Decode a native segwit address into witness version, program hex, and script pubkey.
- [Asn1 oid parse](/tools/asn1-oid-parse): Parse an X.680 object identifier value into numeric arcs and dotted form.
