Segwit address validate
segwit-address-validate · version 1.0.0 · Encoding & checksums · free, no key needed
Validate a native segwit address and report which Bech32 or Bech32m rule failed.
Use when you need to: validate native segwit address · check segwit address checksum variant · check witness program length rules.
Decide before calling
Read the versioned contract and the supported scope below. Reuse segwit-address-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 segwit-address-validate@1.0.0 for validate native segwit address. 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
- validate native segwit address
- check segwit address checksum variant
- check witness program length rules
- is this segwit address well formed
- detect mixed case segwit address
- check segwit address against expected hrp
- validate bech32m witness address
Not supported
- return the witness program bytes
- encode a new segwit address
- prove the program is a key or a payment hash
- repair an invalid checksum
Behavior
- expected_hrp must already be lowercase US-ASCII (code points 33..126 excluding 65..90). An uppercase expected_hrp such as BC is invalid_input with details.reason invalid_hrp and is not case-folded.
- A well-typed address inside the length limits returns {valid:false, reason} for a witness-rule failure and {valid:true, encoding, witness_version, program_length} for success. It does not return the program or the script pubkey.
- Version 0 requires Bech32 and a 20-byte or 32-byte program. Versions 1 through 16 require Bech32m and a 2-to-40-byte program. The other checksum constant yields reason wrong_encoding.
- Rule order for a verdict: character range, mixed case, separator, checksum, empty data, padding, program length, witness version, version-0 length, checksum variant, then exact HRP equality with expected_hrp.
- Wrong types, unknown fields, an empty address, a lone surrogate, and a non-lowercase expected_hrp throw invalid_input. Address length above 90, or expected_hrp length above 83, throws limit_exceeded before those rules. The address limit is checked first.
- Success does not mean the program is a hash, a public key, or a spendable output. The bytes are not inspected past the length rules.
- Disclaimer: format transform only; provides no confidentiality, integrity, or authenticity.
Input
address(string, required): min length 1; max length 90expected_hrp(string, required): min length 1; max length 83; pattern^[\x21-\x40\x5b-\x7e]+$
Output
valid(boolean, required)reason(one of "mixed_case", "character_out_of_range", "no_separator", "empty_hrp", "too_short_checksum", "invalid_character", "bad_checksum", "empty_data", "invalid_padding", "invalid_program_length", "invalid_witness_version", "wrong_encoding", "hrp_mismatch", optional)encoding(one of "bech32", "bech32m", optional)witness_version(integer, optional): min 0; max 16program_length(integer, optional): min 2; max 40
Limits
- max address chars: 90
- max hrp chars: 83
Example
Request input:
{
"address": "BC1SW50QGDZ25J",
"expected_hrp": "bc"
}
Response:
{
"result": {
"valid": true,
"encoding": "bech32m",
"witness_version": 16,
"program_length": 2
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "segwit-address-validate",
"version": "1.0.0",
"input": {
"address": "BC1SW50QGDZ25J",
"expected_hrp": "bc"
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/segwit-address-validate/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"address":"BC1SW50QGDZ25J","expected_hrp":"bc"}'
The machine-readable contract is at /v1/tools/segwit-address-validate/versions/1.0.0.
CLI
node cli.mjs run segwit-address-validate 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Bech32 validate: Check Bech32 or Bech32m text and return a reason, without throwing when the checksum fails.
- Pem label validate: Check a PEM label against the RFC 7468 label grammar, without reading a payload.
- Segwit address encode: Encode a witness program as a native segwit address using Bech32 for v0 and Bech32m for v1-v16.
- Pem envelope validate: Check one RFC 7468 PEM envelope for labels, whitespace, and strict base64.
- Segwit address decode: Decode a native segwit address into witness version, program hex, and script pubkey.
- Bech32 decode: Decode Bech32 or Bech32m text into a lowercase HRP, 5-bit data, and the checksum variant.