Bitcoin Core 31.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
bech32 Namespace Reference

Classes

struct  DecodeResult

Enumerations

enum class  Encoding { INVALID , BECH32 , BECH32M }
enum  CharLimit : size_t { BECH32 = 90 }
 Character limits for Bech32(m) encoded strings. More...

Functions

std::string Encode (Encoding encoding, const std::string &hrp, const data &values)
 Encode a Bech32 or Bech32m string.
DecodeResult Decode (const std::string &str, CharLimit limit)
 Decode a Bech32 or Bech32m string.
std::pair< std::string, std::vector< int > > LocateErrors (const std::string &str, CharLimit limit)
 Find index of an incorrect character in a Bech32 string.
std::string Encode (Encoding encoding, const std::string &hrp, const std::vector< uint8_t > &values)
 Encode a Bech32 or Bech32m string.

Variables

static constexpr size_t CHECKSUM_SIZE = 6
static constexpr char SEPARATOR = '1'

Enumeration Type Documentation

◆ CharLimit

enum bech32::CharLimit : size_t

Character limits for Bech32(m) encoded strings.

Character limits are how we provide error location guarantees. These values should never exceed 2^31 - 1 (max value for a 32-bit int), since there are places where we may need to convert the CharLimit::VALUE to an int. In practice, this should never happen since this CharLimit applies to an address encoding and we would never encode an address with such a massive value

Enumerator
BECH32 

BIP173/350 imposed character limit for Bech32(m) encoded addresses. This guarantees finding up to 4 errors.

Definition at line 38 of file bech32.h.

◆ Encoding

enum class bech32::Encoding
strong
Enumerator
INVALID 

Failed decoding.

BECH32 

Bech32 encoding as defined in BIP173.

BECH32M 

Bech32m encoding as defined in BIP350.

Definition at line 27 of file bech32.h.

Function Documentation

◆ Decode()

DecodeResult bech32::Decode ( const std::string & str,
CharLimit limit )

Decode a Bech32 or Bech32m string.

Definition at line 374 of file bech32.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Encode() [1/2]

std::string bech32::Encode ( Encoding encoding,
const std::string & hrp,
const data & values )

Encode a Bech32 or Bech32m string.

Definition at line 358 of file bech32.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Encode() [2/2]

std::string bech32::Encode ( Encoding encoding,
const std::string & hrp,
const std::vector< uint8_t > & values )

Encode a Bech32 or Bech32m string.

If hrp contains uppercase characters, this will cause an assertion error. Encoding must be one of BECH32 or BECH32M.

Here is the call graph for this function:

◆ LocateErrors()

std::pair< std::string, std::vector< int > > bech32::LocateErrors ( const std::string & str,
CharLimit limit )

Find index of an incorrect character in a Bech32 string.

Return the positions of errors in a Bech32 string.

Definition at line 403 of file bech32.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ CHECKSUM_SIZE

size_t bech32::CHECKSUM_SIZE = 6
staticconstexpr

Definition at line 24 of file bech32.h.

◆ SEPARATOR

char bech32::SEPARATOR = '1'
staticconstexpr

Definition at line 25 of file bech32.h.