Bech32 validate
bech32-validate · version 1.0.0 · Encoding & checksums · free, no key needed
Check Bech32 or Bech32m text and return a reason, without throwing when the checksum fails.
Use when you need to: check whether bech32 text has a valid checksum · check whether bech32m text has a valid checksum · report a reason when bech32 text is rejected.
Decide before calling
Read the versioned contract and the supported scope below. Reuse bech32-validate@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-validate@1.0.0 for check whether bech32 text has a valid checksum. 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
- check whether bech32 text has a valid checksum
- check whether bech32m text has a valid checksum
- report a reason when bech32 text is rejected
- detect mixed case without decoding symbols
- bech32 validation of separator and hrp
- bech32m validation of the 2bc830a3 constant
- say if a checksummed string is empty or too short
- validate bech32 text and keep going on a bad checksum
Not supported
- return the 5-bit symbol array
- repair an invalid checksum
- decide bech32 versus bech32m from a witness version
- convert between 8-bit bytes and 5-bit symbols
Behavior
- Well-typed text that fails the format returns {valid:false, reason}. It throws only for a non-object, unknown or missing fields, a non-string, NaN, Infinity, a lone surrogate, or more than 90 characters.
- reason is ok, empty, mixed_case, no_separator, empty_hrp, hrp_character, data_character, short_checksum, or bad_checksum. Checks run in that order after the length limit.
- A valid string reports the lowercase HRP, data_length (checksum excluded), and variant. Polymod residue 1 is bech32 (BIP 173). Residue 0x2bc830a3 is bech32m (BIP 350).
- All-uppercase is allowed and is not mixed case. An uppercase HRP whose checksum was computed without lowercasing fails as bad_checksum, matching BIP 173 vector A1G7SGD8.
- Segwit program length, witness version, and padding of the converted program are not checked.
- Disclaimer: format transform only; provides no confidentiality, integrity, or authenticity.
Input
text(string, required): min length 0; max length 90
Output
valid(boolean, required)reason(one of "ok", "empty", "mixed_case", "no_separator", "empty_hrp", "hrp_character", "data_character", "short_checksum", "bad_checksum", required)variant(one of "bech32", "bech32m", null, required)hrp(string, required): min length 0; max length 83; pattern^[\x21-\x40\x5b-\x7e]*$data_length(integer, required): min 0; max 82
Limits
- max text chars: 90
Example
Request input:
{
"text": "a12uel5l"
}
Response:
{
"result": {
"valid": true,
"reason": "ok",
"variant": "bech32",
"hrp": "a",
"data_length": 0
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "bech32-validate",
"version": "1.0.0",
"input": {
"text": "a12uel5l"
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/bech32-validate/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"text":"a12uel5l"}'
The machine-readable contract is at /v1/tools/bech32-validate/versions/1.0.0.
CLI
node cli.mjs run bech32-validate 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Bech32 decode: Decode Bech32 or Bech32m text into a lowercase HRP, 5-bit data, and the checksum variant.
- Bech32 encode: Encode lowercase HRP and 5-bit data as Bech32 or Bech32m text using that checksum.
- Segwit address validate: Validate a native segwit address and report which Bech32 or Bech32m rule failed.
- Bech32 convert bits: Regroup integers between bit widths using BIP 173 rules, rejecting bad leftover padding.
- Pem envelope validate: Check one RFC 7468 PEM envelope for labels, whitespace, and strict base64.
- Ct merkle root compute: Compute the RFC 6962 v1 domain-separated Merkle Tree Hash of raw leaves.