MPP.Hex (mpp v0.10.0)

Copy Markdown View Source

Small internal hex-string helpers shared across the payment-method and wire-format modules.

These cover two string-level checks that are used before length/format validation of Ethereum-style hex addresses and calldata:

  • strip_0x/1 — drop an optional 0x prefix, returning the rest unchanged.
  • hex_string?/1 — true when the (already prefix-stripped) string is one or more bare hex digits, with no 0x prefix.

For decode/encode/integer conversion use Onchain.Hex (decode/1, encode/1, to_integer/1, valid?/1). Note Onchain.Hex.valid?/1 accepts a 0x prefix, whereas hex_string?/1 here does not — they are not interchangeable.

Summary

Functions

Return true when str is one or more bare hex digits (0-9a-fA-F), with no 0x prefix. An empty string is not valid hex.

Drop an optional leading 0x prefix, returning the remaining string unchanged.

Functions

hex_string?(str)

@spec hex_string?(String.t()) :: boolean()

Return true when str is one or more bare hex digits (0-9a-fA-F), with no 0x prefix. An empty string is not valid hex.

strip_0x(hex)

@spec strip_0x(String.t()) :: String.t()

Drop an optional leading 0x prefix, returning the remaining string unchanged.