Skip to main content

Module hex

Module hex 

Source
Expand description

Hex parsing + encoding helpers.

Replaces the s.strip_prefix("0x").unwrap_or(s); hex::decode(s) pattern duplicated across nine sites in the wallet / runtime / cli crates. All parsers accept 0x-prefixed and bare-hex input.

Enums§

HexError

Functions§

is_hex
true iff s parses as hex (with or without 0x). When byte_len is Some(n), also requires the decoded length to equal n bytes — handy for “is this a valid 32-byte hash” checks.
parse_hex
Parse a hex string (with or without 0x prefix) into bytes.
parse_hex_n
Parse a hex string into a fixed-size byte array. Errors when the decoded length doesn’t match N. Useful for IDs, hashes, public-key bytes that must be exactly N bytes.
to_hex
Lowercase hex without 0x prefix.
to_hex_prefixed
Lowercase hex with 0x prefix.