bech32-kit

Pure MoonBit Bech32/Bech32m codec and SegWit address validator.

bech32
bech32m
segwit
checksum
encoding
moon add MM-ai-nb/bech32-kit@0.1.0
Download zip
Author
Version
0.1.0
License
MIT
Last updated
6 hours ago
Downloads
3
README

#bech32-kit

bech32-kit 是一个纯 MoonBit 实现的 Bech32 / Bech32m 编码、解码、校验、诊断分析、策略校验、文本扫描和 SegWit 地址验证库。它面向需要在 MoonBit 或 WebAssembly 场景中处理紧凑校验字符串、钱包地址、链上工具、配置短码、日志文本和协议字段的开发者。

#项目解决的问题

Bech32 和 Bech32m 常用于低误读率的人类可读编码。MoonBit 生态中这类基础编码库仍然较少,项目提供可复用的 MoonBit 原生实现,避免上层项目临时复制 checksum 逻辑或依赖外部运行时。库会返回结构化错误、稳定的校验报告、策略拒绝原因和文本扫描结果,便于调用者区分 checksum 错误、大小写错误、非法字符、bit 转换错误、HRP 不匹配、网络不匹配、非规范地址和 SegWit 规则错误。

#适用场景

  • MoonBit 钱包工具或链上数据工具;
  • SegWit 地址编码、解码和输入校验;
  • WebAssembly 应用中的地址格式检查;
  • CLI 工具中的 Bech32 / Bech32m 字符串处理;
  • 日志、剪贴板文本、表单备注中的地址候选串扫描;
  • 地址导入流程中的 HRP / 网络 / Taproot 策略校验;
  • 协议测试 fixture 生成和教学项目中的编码算法演示。

#安装方式

moon add MM-ai-nb/bech32-kit

Mooncakes 包名:

MM-ai-nb/bech32-kit

包名已与 moon.mod 保持一致;正式发布时请使用 MM-ai-nb 对应的 Mooncakes 登录会话。

#最小使用示例

let encoded = @bech32.encode("moon", [0, 1, 2, 3, 4]).unwrap()
let decoded = @bech32.decode(encoded).unwrap()
println(decoded.hrp)

诊断示例:

let report = @bech32.validation_report("A12UEL5L")
println(report.valid)
println(report.variant)

let info = @bech32.inspect("A12UEL5L").unwrap()
println(@bech32.case_style_name(info.case_style))

文本扫描和策略校验示例:

let report = @bech32.scan_segwit_text("pay bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4")
println(report.segwit_valid)

let policy = @bech32.bitcoin_mainnet_segwit_policy()
let check = @bech32.check_with_policy(
"bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",
policy,
)
println(check.accepted)

可运行示例:

moon run cmd/main

示例会输出一个 Bech32 SegWit v0 地址:

bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4

#核心功能

  • encode / decode:Bech32 编码、解码与 checksum 验证;
  • encode_m / encode_with_variant:Bech32m 或显式变体编码;
  • convert_bits:通用 bit group 转换,支持 canonical padding 校验;
  • encode_bytes / decode_bytes:字节数组与 Bech32 数据互转;
  • encode_segwit / decode_segwit:BIP-0173 和 BIP-0350 SegWit 地址编码与验证;
  • is_valid / is_valid_segwit:快速布尔校验接口;
  • profile / inspect:输入结构分析、checksum word 提取和规范化信息;
  • validation_report / validate_many:面向 CLI 或 UI 的单条与批量校验报告;
  • diagnose / diagnose_segwit / summarize_diagnostics:带 severity、recommendation 和 hints 的诊断报告;
  • check_with_policy / summarize_policy_inputs:按 Bech32、Bech32m、HRP、payload 长度、SegWit 网络和 program kind 执行高层策略校验;
  • scan_text / scan_segwit_text / scan_lines_with_options:从自由文本或多行文本中提取候选串并批量诊断;
  • lint_scan_report / render_scan_report:对扫描结果输出策略问题、重复候选和可打印报告;
  • normalize / is_canonical / hrp_of / data_words_of / checksum_words_of:常用提取和规范化工具;
  • segwit_network / inspect_segwit / decode_segwit_on_network:SegWit 网络识别、witness program 分类和网络防误用校验;
  • error_code / error_message:稳定错误码和可展示错误文案;
  • Bech32Error:结构化错误枚举,覆盖主要失败路径。

#项目文档

  • API.md:公开 API、数据类型和错误说明;
  • DESIGN.md:技术方案、测试策略和功能边界;
  • TASK_REPORT.md:任务报告书与验收条件对照;
  • SUBMISSION.md:项目申报书;
  • 卓娟-MoonBit八月黑客松项目申报书.md:可直接提交的 Markdown 版申报书;
  • MOONCAKES.md:Mooncakes 发布准备、命令和状态记录;
  • CHANGELOG.md:版本更新记录;
  • docs/任务报告书-卓娟-bech32-kit.docx:可提交的 Word 版任务报告书。

#支持范围

  • Bech32 checksum 常量 1
  • Bech32m checksum 常量 0x2bc830a3
  • HRP 可打印 ASCII 范围校验;
  • 整串大小写一致性校验与小写规范化输出;
  • 5-bit 数据值范围校验;
  • SegWit witness version 0..16
  • SegWit v0 程序长度 2032 字节;
  • SegWit v1 到 v16 使用 Bech32m 的规则校验;
  • Bitcoin mainnet / testnet / regtest HRP 识别;
  • P2WPKH、P2WSH、Taproot 常见 witness program 分类;
  • 批量输入校验统计和稳定错误报告输出;
  • 可配置策略校验,覆盖 canonical、variant、HRP、payload 长度、SegWit 网络和 witness program 类型;
  • 文本候选串扫描,支持普通 Bech32、SegWit 专用模式、网络过滤、HRP 过滤、重复候选识别和无效候选诊断。

#暂不支持范围

  • 自动纠错或错误位置建议;
  • 文件系统扫描、网络请求或钱包私钥处理;文本扫描仅处理调用者传入的字符串;
  • Unicode HRP,Bech32 标准 HRP 使用可打印 ASCII;
  • 超出 90 字符限制的非标准扩展编码。

#本地运行与验收

moon fmt --check moon check --deny-warn moon build moon test --deny-warn moon run cmd/main moon info

moon publish --dry-runmoon publish 需要使用 MM-ai-nb 对应的 Mooncakes 登录会话,避免账号信息混淆。

测试覆盖正常向量、错误输入、边界条件、bit 转换、字节导出、诊断报告、批量校验、策略校验、文本扫描、SegWit v0/v1 编解码、网络识别与主要错误路径。

#开源许可证与参考说明

项目采用 MIT License。实现参考公开标准 BIP-0173(Bech32)与 BIP-0350(Bech32m)的算法描述和测试向量,未移植第三方源码,不包含外部素材或私有代码。

#
Bech32Error

pub(all) enum Bech32Error {
EmptyInput
TooLong(Int)
MissingSeparator
EmptyHrp
EmptyData
MixedCase
InvalidHrpChar(Char, Int)
InvalidDataChar(Char, Int)
InvalidDataValue(Int, Int)
InvalidChecksum
InvalidBitGroup(Int, Int)
InvalidPadding
InvalidWitnessVersion(Int)
InvalidWitnessProgramLength(Int, Int)
InvalidWitnessEncoding(Variant, Variant)
UnexpectedHrp(String, String)
UnexpectedNetwork(SegwitNetwork, SegwitNetwork)
} derive(Eq,
Debug
)

Structured errors returned by the parser and validators.

#
Bech32Info

pub(all) struct Bech32Info {
input : String
normalized : String
hrp : String
data : Array[Int]
checksum : Array[Int]
variant : Variant
total_length : Int
separator_index : Int
data_part_length : Int
data_length : Int
checksum_length : Int
case_style : CaseStyle
segwit_valid : Bool
} derive(Eq,
Debug
)

Detailed information for a valid Bech32 or Bech32m string.

#
Bech32Policy

pub(all) struct Bech32Policy {
name : String
allow_any_hrp : Bool
allowed_hrps : Array[String]
allow_bech32 : Bool
allow_bech32m : Bool
require_canonical : Bool
require_segwit : Bool
allow_any_network : Bool
allowed_networks : Array[String]
allow_any_program_kind : Bool
allowed_program_kinds : Array[String]
min_payload_words : Int
max_payload_words : Int
} derive(Eq,
Debug
)

Higher-level acceptance policy built on top of Bech32 and SegWit validation.

#
CandidateSpan

pub(all) struct CandidateSpan {
text : String
start_offset : Int
end_offset : Int
length : Int
line_number : Int
column_number : Int
} derive(Eq,
Debug
)

Location of one extracted candidate.

#
CaseStyle

pub(all) enum CaseStyle {
CaseNoLetters
CaseLower
CaseUpper
CaseMixed
} derive(Eq,
Debug
)

Letter-case classification for Bech32 input strings.

#
ComparisonReport

pub(all) struct ComparisonReport {
left_input : String
right_input : String
left_valid : Bool
right_valid : Bool
left_segwit_valid : Bool
right_segwit_valid : Bool
left_canonical : Bool
right_canonical : Bool
left_variant : String
right_variant : String
left_case_style : CaseStyle
right_case_style : CaseStyle
left_hrp : String
right_hrp : String
left_network : String
right_network : String
left_program_kind : String
right_program_kind : String
left_error_code : String
right_error_code : String
same_validity : Bool
same_segwit_validity : Bool
same_canonicality : Bool
same_variant : Bool
same_case_style : Bool
same_hrp : Bool
same_network : Bool
same_program_kind : Bool
same_error_code : Bool
same_length : Bool
difference_count : Int
} derive(Eq,
Debug
)

Comparison between two diagnostics.

#
Decoded

pub(all) struct Decoded {
hrp : String
data : Array[Int]
variant : Variant
} derive(Eq,
Debug
)

A decoded Bech32 or Bech32m string. data contains 5-bit values with the six checksum words removed.

#
Diagnostic

pub(all) struct Diagnostic {
input : String
normalized : String
valid : Bool
segwit_valid : Bool
canonical : Bool
severity : DiagnosticSeverity
recommendation : DiagnosticRecommendation
case_style : CaseStyle
variant : String
hrp : String
network : String
program_kind : String
error_code : String
error_message : String
hints : Array[String]
} derive(Eq,
Debug
)

Diagnostic result for one input string.

#
DiagnosticRecommendation

pub(all) enum DiagnosticRecommendation {
RecommendNone
RecommendNormalizeInput
RecommendLowercaseInput
RecommendCheckSeparator
RecommendCheckHrp
RecommendCheckCharset
RecommendCheckChecksum
RecommendCheckPadding
RecommendCheckWitnessVersion
RecommendCheckWitnessProgramLength
RecommendUseBech32
RecommendUseBech32m
RecommendCheckNetwork
RecommendCheckByteConversion
} derive(Eq,
Debug
)

Recommended next step for a failed or non-canonical input.

#
DiagnosticSeverity

pub(all) enum DiagnosticSeverity {
DiagnosticOk
DiagnosticInfo
DiagnosticWarning
DiagnosticError
} derive(Eq,
Debug
)

Severity for diagnostic output.

#
InputProfile

pub(all) struct InputProfile {
input : String
normalized : String
total_length : Int
separator_index : Int
hrp_length : Int
data_part_length : Int
payload_length : Int
checksum_length : Int
case_style : CaseStyle
has_separator : Bool
has_checksum : Bool
} derive(Eq,
Debug
)

Mechanical profile of an input string. This is available even for malformed inputs and is useful for command-line diagnostics.

#
PolicyCheck

pub(all) struct PolicyCheck {
input : String
policy_name : String
accepted : Bool
valid : Bool
segwit_valid : Bool
canonical : Bool
variant : String
hrp : String
network : String
program_kind : String
payload_words : Int
failure : PolicyFailureKind
failure_code : String
failure_message : String
recommendation : String
} derive(Eq,
Debug
)

Result of applying a high-level policy to one input.

#
PolicyFailureKind

pub(all) enum PolicyFailureKind {
PolicyFailureNone
PolicyFailureInvalidBech32(String)
PolicyFailureNotCanonical
PolicyFailureVariantNotAllowed(String)
PolicyFailureHrpNotAllowed(String)
PolicyFailurePayloadTooShort(Int, Int)
PolicyFailurePayloadTooLong(Int, Int)
PolicyFailureSegwitRequired
PolicyFailureNetworkNotAllowed(String)
PolicyFailureProgramKindNotAllowed(String)
} derive(Eq,
Debug
)

Failure reason produced by policy-level validation.

#
PolicySummary

pub(all) struct PolicySummary {
policy_name : String
total : Int
accepted : Int
rejected : Int
rejected_invalid : Int
rejected_not_canonical : Int
rejected_variant : Int
rejected_hrp : Int
rejected_payload_too_short : Int
rejected_payload_too_long : Int
rejected_segwit_required : Int
rejected_network : Int
rejected_program_kind : Int
} derive(Eq,
Debug
)

Aggregated policy-check result for a batch.

#
ScanBoundaryStyle

pub(all) enum ScanBoundaryStyle {
ScanBoundaryLoose
ScanBoundaryToken
ScanBoundaryStrict
} derive(Eq,
Debug
)

Boundary policy used when extracting candidates from a larger text.

#
ScanFinding

pub(all) struct ScanFinding {
span : CandidateSpan
diagnostic : Diagnostic
accepted : Bool
reason : String
duplicate_of : Int
} derive(Eq,
Debug
)

One candidate and its diagnostic output.

#
ScanIssue

pub(all) struct ScanIssue {
kind : ScanIssueKind
severity : DiagnosticSeverity
finding_index : Int
related_index : Int
input : String
normalized : String
message : String
recommendation : DiagnosticRecommendation
} derive(Eq,
Debug
)

A policy issue derived from scan findings.

#
ScanIssueKind

pub(all) enum ScanIssueKind {
ScanIssueInvalidCandidate
ScanIssueNonCanonical
ScanIssueNotSegwit
ScanIssueUnexpectedHrp
ScanIssueUnexpectedNetwork
ScanIssueNonStandardNetwork
ScanIssueMixedCase
ScanIssueUppercase
ScanIssueDuplicate
} derive(Eq,
Debug
)

Policy issue emitted by scan lint helpers.

#
ScanMode

pub(all) enum ScanMode {
ScanGeneric
ScanSegwit
} derive(Eq,
Debug
)

Scan mode for text extraction helpers.

#
ScanOptions

pub(all) struct ScanOptions {
min_length : Int
max_length : Int
include_invalid : Bool
mode : ScanMode
require_canonical : Bool
require_standard_segwit_hrp : Bool
expected_hrp : String
expected_network : String
accept_uppercase : Bool
accept_mixed_case : Bool
boundary_style : ScanBoundaryStyle
deduplicate : Bool
} derive(Eq,
Debug
)

Options for extracting Bech32-like candidates from text.

#
ScanReport

pub(all) struct ScanReport {
source : String
findings : Array[ScanFinding]
summary : ValidationSummary
total_candidates : Int
accepted : Int
rejected : Int
valid : Int
invalid : Int
segwit_valid : Int
canonical : Int
duplicate : Int
} derive(Eq,
Debug
)

Aggregated scan output.

#
SegwitAddress

pub(all) struct SegwitAddress {
hrp : String
version : Int
program : Array[Int]
variant : Variant
} derive(Eq,
Debug
)

A decoded BIP-0173/BIP-0350 SegWit address.

#
SegwitInfo

pub(all) struct SegwitInfo {
input : String
normalized : String
hrp : String
version : Int
program : Array[Int]
program_length : Int
variant : Variant
network : SegwitNetwork
program_kind : WitnessProgramKind
} derive(Eq,
Debug
)

Detailed information for a valid SegWit address.

#
SegwitNetwork

pub(all) enum SegwitNetwork {
NetworkBitcoinMainnet
NetworkBitcoinTestnet
NetworkBitcoinRegtest
NetworkUnknown(String)
} derive(Eq,
Debug
)

Common SegWit network names inferred from the human-readable part.

#
ValidationReport

pub(all) struct ValidationReport {
input : String
normalized : String
valid : Bool
segwit_valid : Bool
variant : String
hrp : String
error_code : String
error_message : String
total_length : Int
separator_index : Int
data_part_length : Int
} derive(Eq,
Debug
)

Stable validation report for batch tools. String fields are intentionally presentation-ready so callers can print reports without matching every enum.

#
ValidationSummary

pub(all) struct ValidationSummary {
total : Int
valid : Int
invalid : Int
segwit_valid : Int
canonical : Int
ok : Int
info : Int
warning : Int
error : Int
case_no_letters : Int
case_lower : Int
case_upper : Int
case_mixed : Int
variant_bech32 : Int
variant_bech32m : Int
network_mainnet : Int
network_testnet : Int
network_regtest : Int
network_unknown : Int
program_p2wpkh : Int
program_p2wsh : Int
program_taproot : Int
program_other : Int
recommend_none : Int
recommend_normalize_input : Int
recommend_lowercase_input : Int
recommend_check_separator : Int
recommend_check_hrp : Int
recommend_check_charset : Int
recommend_check_checksum : Int
recommend_check_padding : Int
recommend_check_witness_version : Int
recommend_check_witness_program_length : Int
recommend_use_bech32 : Int
recommend_use_bech32m : Int
recommend_check_network : Int
recommend_check_byte_conversion : Int
error_empty_input : Int
error_too_long : Int
error_missing_separator : Int
error_empty_hrp : Int
error_empty_data : Int
error_mixed_case : Int
error_invalid_hrp_char : Int
error_invalid_data_char : Int
error_invalid_data_value : Int
error_invalid_checksum : Int
error_invalid_bit_group : Int
error_invalid_padding : Int
error_invalid_witness_version : Int
error_invalid_witness_program_length : Int
error_invalid_witness_encoding : Int
error_unexpected_hrp : Int
error_unexpected_network : Int
} derive(Eq,
Debug
)

Aggregated diagnostic counts over a batch of inputs.

#
Variant

pub(all) enum Variant {
Bech32
Bech32m
} derive(Eq,
Debug
)

Bech32 checksum variant.

#
WitnessProgramKind

pub(all) enum WitnessProgramKind {
WitnessProgramP2WPKH
WitnessProgramP2WSH
WitnessProgramTaproot
WitnessProgramOther
} derive(Eq,
Debug
)

Common witness program categories useful for wallet and indexer diagnostics.

#
accepted_inputs

fn accepted_inputs(inputs : Array[String], policy : Bech32Policy) -> Array[String]

#
all_valid

fn all_valid(inputs : Array[String]) -> Bool

Returns true when every input in a batch is valid.

#
any_bech32_policy

fn any_bech32_policy() -> Bech32Policy

#
bech32_only_policy

fn bech32_only_policy() -> Bech32Policy

#
bech32m_only_policy

fn bech32m_only_policy() -> Bech32Policy

#
bitcoin_mainnet_segwit_policy

fn bitcoin_mainnet_segwit_policy() -> Bech32Policy

#
bitcoin_regtest_segwit_policy

fn bitcoin_regtest_segwit_policy() -> Bech32Policy

#
bitcoin_segwit_policy

fn bitcoin_segwit_policy() -> Bech32Policy

#
bitcoin_testnet_segwit_policy

fn bitcoin_testnet_segwit_policy() -> Bech32Policy

#
canonical_bech32_policy

fn canonical_bech32_policy() -> Bech32Policy

#
canonical_scan_findings

fn canonical_scan_findings(findings : Array[ScanFinding]) -> Array[ScanFinding]

#
case_style_name

fn case_style_name(style : CaseStyle) -> String

Returns a stable lowercase display name for input letter-case style.

#
check_many_with_policy

fn check_many_with_policy(inputs : Array[String], policy : Bech32Policy) -> Array[PolicyCheck]

#
check_with_policy

fn check_with_policy(input : String, policy : Bech32Policy) -> PolicyCheck

#
checksum_words_of

fn checksum_words_of(input : String) -> Result[Array[Int], Bech32Error]

Extracts the six checksum words after full checksum validation.

#
classify_case

fn classify_case(input : String) -> CaseStyle

Classifies whether an input is lowercase, uppercase, mixed-case, or has no ASCII letters. Bech32 accepts only all-lowercase or all-uppercase strings.

#
compare_diagnostics

fn compare_diagnostics(left : Diagnostic, right : Diagnostic) -> ComparisonReport

#
compare_inputs

fn compare_inputs(left : String, right : String) -> ComparisonReport

#
comparison_hints

fn comparison_hints(report : ComparisonReport) -> Array[String]

#
convert_bits

fn convert_bits(data : Array[Int], from_bits : Int, to_bits : Int, pad : Bool) -> Result[Array[Int], Bech32Error]

Converts an array of unsigned integer groups from one bit width to another. Use pad=false when decoding canonical encodings back to bytes.

#
data_words_of

fn data_words_of(input : String) -> Result[Array[Int], Bech32Error]

Extracts payload data words after full checksum validation.

#
decode

fn decode(input : String) -> Result[Decoded, Bech32Error]

Decodes a Bech32 or Bech32m string and verifies its checksum.

#
decode_bytes

fn decode_bytes(input : String) -> Result[(String, Array[Int], Variant), Bech32Error]

Decodes Bech32 data back to byte values (0..255).

#
decode_segwit

fn decode_segwit(input : String) -> Result[SegwitAddress, Bech32Error]

Decodes and validates a SegWit address.

#
decode_segwit_on_network

fn decode_segwit_on_network(input : String, expected : SegwitNetwork) -> Result[SegwitAddress, Bech32Error]

Decodes a SegWit address and additionally checks the expected network.

#
decode_with_hrp

fn decode_with_hrp(input : String, expected_hrp : String) -> Result[Decoded, Bech32Error]

Decodes an input and additionally checks the expected HRP.

#
default_scan_options

fn default_scan_options() -> ScanOptions

#
diagnose

fn diagnose(input : String) -> Diagnostic

#
diagnose_many

fn diagnose_many(inputs : Array[String]) -> Array[Diagnostic]

#
diagnose_segwit

fn diagnose_segwit(input : String) -> Diagnostic

#
diagnose_segwit_many

fn diagnose_segwit_many(inputs : Array[String]) -> Array[Diagnostic]

#
encode

fn encode(hrp : String, data : Array[Int]) -> Result[String, Bech32Error]

Encodes 5-bit data words with a Bech32 checksum.

#
encode_bytes

fn encode_bytes(hrp : String, bytes : Array[Int], variant : Variant) -> Result[String, Bech32Error]

Encodes byte values (0..255) as Bech32 data.

#
encode_m

fn encode_m(hrp : String, data : Array[Int]) -> Result[String, Bech32Error]

Encodes 5-bit data words with a Bech32m checksum.

#
encode_segwit

fn encode_segwit(hrp : String, version : Int, program : Array[Int]) -> Result[String, Bech32Error]

Encodes a SegWit address. Version 0 uses Bech32; versions 1 through 16 use Bech32m, as required by BIP-0350.

#
encode_with_variant

fn encode_with_variant(hrp : String, data : Array[Int], variant : Variant) -> Result[String, Bech32Error]

Encodes 5-bit data words with the selected checksum variant.

#
error_code

fn error_code(err : Bech32Error) -> String

Stable machine-readable code for every structured error.

#
error_message

fn error_message(err : Bech32Error) -> String

Human-readable message for every structured error.

#
filter_scan_findings_by_hrp

fn filter_scan_findings_by_hrp(findings : Array[ScanFinding], hrp : String) -> Array[ScanFinding]

#
filter_scan_findings_by_network

fn filter_scan_findings_by_network(findings : Array[ScanFinding], network : String) -> Array[ScanFinding]

#
first_policy_failure

fn first_policy_failure(inputs : Array[String], policy : Bech32Policy) -> PolicyCheck?

#
first_segwit_scan_finding

fn first_segwit_scan_finding(report : ScanReport) -> ScanFinding?

#
first_valid_scan_finding

fn first_valid_scan_finding(report : ScanReport) -> ScanFinding?

#
hrp_of

fn hrp_of(input : String) -> Result[String, Bech32Error]

Extracts the HRP after full checksum validation.

#
inspect

fn inspect(input : String) -> Result[Bech32Info, Bech32Error]

Inspects a valid Bech32 or Bech32m string and returns printable metadata.

#
inspect_segwit

fn inspect_segwit(input : String) -> Result[SegwitInfo, Bech32Error]

Inspects a valid SegWit address and returns network and witness metadata.

#
invalid_count

fn invalid_count(inputs : Array[String]) -> Int

Counts invalid Bech32 or Bech32m strings in a batch.

#
invalid_scan_findings

fn invalid_scan_findings(findings : Array[ScanFinding]) -> Array[ScanFinding]

#
is_bech32

fn is_bech32(input : String) -> Bool

Returns true only for valid Bech32 strings.

#
is_bech32m

fn is_bech32m(input : String) -> Bool

Returns true only for valid Bech32m strings.

#
is_canonical

fn is_canonical(input : String) -> Bool

Returns true when an input is valid and already in canonical lowercase form.

#
is_standard_segwit_hrp

fn is_standard_segwit_hrp(hrp : String) -> Bool

Returns true for standard Bitcoin SegWit HRPs: bc, tb, and bcrt.

#
is_valid

fn is_valid(input : String) -> Bool

Returns true when input is a valid Bech32 or Bech32m string.

#
is_valid_segwit

fn is_valid_segwit(input : String) -> Bool

Returns true when input is a valid SegWit address.

#
lint_scan_report

fn lint_scan_report(report : ScanReport, options : ScanOptions) -> Array[ScanIssue]

#
network_name

fn network_name(network : SegwitNetwork) -> String

Returns a stable display name for a SegWit network classification.

#
non_canonical_scan_findings

fn non_canonical_scan_findings(findings : Array[ScanFinding]) -> Array[ScanFinding]

#
normalize

fn normalize(input : String) -> Result[String, Bech32Error]

Returns a lowercase canonical representation after checksum validation.

#
policy_accepts

fn policy_accepts(input : String, policy : Bech32Policy) -> Bool

#
policy_failure_code

fn policy_failure_code(failure : PolicyFailureKind) -> String

#
policy_failure_message

fn policy_failure_message(failure : PolicyFailureKind) -> String

#
policy_failure_recommendation

fn policy_failure_recommendation(failure : PolicyFailureKind) -> String

#
policy_rejects

fn policy_rejects(input : String, policy : Bech32Policy) -> Bool

#
policy_requiring_canonical

fn policy_requiring_canonical(policy : Bech32Policy, required : Bool) -> Bech32Policy

#
policy_with_hrps

fn policy_with_hrps(policy : Bech32Policy, hrps : Array[String]) -> Bech32Policy

#
policy_with_name

fn policy_with_name(policy : Bech32Policy, name : String) -> Bech32Policy

#
policy_with_payload_bounds

fn policy_with_payload_bounds(policy : Bech32Policy, min_payload_words : Int, max_payload_words : Int) -> Bech32Policy

#
profile

fn profile(input : String) -> InputProfile

Builds a structural profile without validating checksum or character set.

#
recommendation_message

fn recommendation_message(recommendation : DiagnosticRecommendation) -> String

#
recommendation_name

fn recommendation_name(recommendation : DiagnosticRecommendation) -> String

#
rejected_inputs

fn rejected_inputs(inputs : Array[String], policy : Bech32Policy) -> Array[String]

#
render_comparison

fn render_comparison(report : ComparisonReport) -> String

#
render_diagnostic

fn render_diagnostic(diagnostic : Diagnostic) -> String

#
render_policy_check

fn render_policy_check(check : PolicyCheck) -> String

#
render_policy_summary

fn render_policy_summary(summary : PolicySummary) -> String

#
render_scan_finding

fn render_scan_finding(finding : ScanFinding) -> String

#
render_scan_issue

fn render_scan_issue(issue : ScanIssue) -> String

#
render_scan_issues

fn render_scan_issues(issues : Array[ScanIssue]) -> String

#
render_scan_report

fn render_scan_report(report : ScanReport) -> String

#
render_validation_summary

fn render_validation_summary(summary : ValidationSummary) -> String

#
scan_boundary_style_name

fn scan_boundary_style_name(style : ScanBoundaryStyle) -> String

#
scan_finding_hrps

fn scan_finding_hrps(findings : Array[ScanFinding]) -> Array[String]

#
scan_finding_networks

fn scan_finding_networks(findings : Array[ScanFinding]) -> Array[String]

#
scan_finding_normalized_texts

fn scan_finding_normalized_texts(findings : Array[ScanFinding]) -> Array[String]

#
scan_finding_texts

fn scan_finding_texts(findings : Array[ScanFinding]) -> Array[String]

#
scan_issue_count

fn scan_issue_count(issues : Array[ScanIssue]) -> Int

#
scan_issue_error_count

fn scan_issue_error_count(issues : Array[ScanIssue]) -> Int

#
scan_issue_info_count

fn scan_issue_info_count(issues : Array[ScanIssue]) -> Int

#
scan_issue_kind_name

fn scan_issue_kind_name(kind : ScanIssueKind) -> String

#
scan_issue_warning_count

fn scan_issue_warning_count(issues : Array[ScanIssue]) -> Int

#
scan_issues_are_clean

fn scan_issues_are_clean(issues : Array[ScanIssue]) -> Bool

#
scan_lines

fn scan_lines(lines : Array[String]) -> ScanReport

#
scan_lines_with_options

fn scan_lines_with_options(lines : Array[String], options : ScanOptions) -> ScanReport

#
scan_mode_name

fn scan_mode_name(mode : ScanMode) -> String

#
scan_options_accept_mixed_case

fn scan_options_accept_mixed_case(options : ScanOptions, accept_mixed_case : Bool) -> ScanOptions

#
scan_options_accept_uppercase

fn scan_options_accept_uppercase(options : ScanOptions, accept_uppercase : Bool) -> ScanOptions

#
scan_options_boundary_style

fn scan_options_boundary_style(options : ScanOptions, boundary_style : ScanBoundaryStyle) -> ScanOptions

#
scan_options_deduplicate

fn scan_options_deduplicate(options : ScanOptions, deduplicate : Bool) -> ScanOptions

#
scan_options_expected_hrp

fn scan_options_expected_hrp(options : ScanOptions, expected_hrp : String) -> ScanOptions

#
scan_options_expected_network

fn scan_options_expected_network(options : ScanOptions, expected_network : String) -> ScanOptions

#
scan_options_include_invalid

fn scan_options_include_invalid(options : ScanOptions, include_invalid : Bool) -> ScanOptions

#
scan_options_mode

fn scan_options_mode(options : ScanOptions, mode : ScanMode) -> ScanOptions

#
scan_options_require_canonical

fn scan_options_require_canonical(options : ScanOptions, require_canonical : Bool) -> ScanOptions

#
scan_options_require_standard_segwit_hrp

fn scan_options_require_standard_segwit_hrp(options : ScanOptions, require_standard_segwit_hrp : Bool) -> ScanOptions

#
scan_options_with_max_length

fn scan_options_with_max_length(options : ScanOptions, max_length : Int) -> ScanOptions

#
scan_options_with_min_length

fn scan_options_with_min_length(options : ScanOptions, min_length : Int) -> ScanOptions

#
scan_report_all_canonical

fn scan_report_all_canonical(report : ScanReport) -> Bool

#
scan_report_diagnostics

fn scan_report_diagnostics(report : ScanReport) -> Array[Diagnostic]

#
scan_report_has_invalid

fn scan_report_has_invalid(report : ScanReport) -> Bool

#
scan_report_has_segwit

fn scan_report_has_segwit(report : ScanReport) -> Bool

#
scan_report_has_valid

fn scan_report_has_valid(report : ScanReport) -> Bool

#
scan_report_is_clean

fn scan_report_is_clean(report : ScanReport) -> Bool

#
scan_report_is_empty

fn scan_report_is_empty(report : ScanReport) -> Bool

#
scan_segwit_lines

fn scan_segwit_lines(lines : Array[String]) -> ScanReport

#
scan_segwit_text

fn scan_segwit_text(text : String) -> ScanReport

#
scan_text

fn scan_text(text : String) -> ScanReport

#
scan_text_with_options

fn scan_text_with_options(text : String, options : ScanOptions) -> ScanReport

#
segwit_network

fn segwit_network(hrp : String) -> SegwitNetwork

Infers the common SegWit network from an HRP.

#
segwit_network_of

fn segwit_network_of(input : String) -> Result[SegwitNetwork, Bech32Error]

Infers the SegWit network after full SegWit address validation.

#
segwit_scan_findings

fn segwit_scan_findings(findings : Array[ScanFinding]) -> Array[ScanFinding]

#
segwit_scan_options

fn segwit_scan_options() -> ScanOptions

#
segwit_valid_count

fn segwit_valid_count(inputs : Array[String]) -> Int

Counts valid SegWit addresses in a batch.

#
severity_name

fn severity_name(severity : DiagnosticSeverity) -> String

#
summarize_diagnostics

fn summarize_diagnostics(diagnostics : Array[Diagnostic]) -> ValidationSummary

#
summarize_inputs

fn summarize_inputs(inputs : Array[String]) -> ValidationSummary

#
summarize_policy_checks

fn summarize_policy_checks(checks : Array[PolicyCheck]) -> PolicySummary

#
summarize_policy_inputs

fn summarize_policy_inputs(inputs : Array[String], policy : Bech32Policy) -> PolicySummary

#
summarize_segwit_inputs

fn summarize_segwit_inputs(inputs : Array[String]) -> ValidationSummary

#
summary_has_errors

fn summary_has_errors(summary : ValidationSummary) -> Bool

#
summary_has_segwit

fn summary_has_segwit(summary : ValidationSummary) -> Bool

#
summary_is_clean

fn summary_is_clean(summary : ValidationSummary) -> Bool

#
taproot_mainnet_policy

fn taproot_mainnet_policy() -> Bech32Policy

#
valid_count

fn valid_count(inputs : Array[String]) -> Int

Counts valid Bech32 or Bech32m strings in a batch.

#
valid_scan_findings

fn valid_scan_findings(findings : Array[ScanFinding]) -> Array[ScanFinding]

#
validate_many

fn validate_many(inputs : Array[String]) -> Array[ValidationReport]

Validates many inputs while preserving input order.

#
validation_report

fn validation_report(input : String) -> ValidationReport

Produces one validation report that is convenient for CLI and UI callers.

#
variant_name

fn variant_name(variant : Variant) -> String

Returns a stable lowercase display name for a checksum variant.

#
witness_program_kind

fn witness_program_kind(version : Int, program_length : Int) -> WitnessProgramKind

Classifies a witness program by version and program length.

#
witness_program_kind_name

fn witness_program_kind_name(kind : WitnessProgramKind) -> String

Returns a stable display name for a witness program category.