Documentation

Bech32

Table of Contents

Namespaces

Exception

Constants

CHARKEY_KEY  = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, 10, 17, 21, 20, 26, 30, 7, 5, -1, -1, -1, -1, -1, -1, -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1, -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1]
CHARSET  = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'
GENERATOR  = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3]

Functions

polyMod()  : int
hrpExpand()  : array<string|int, int>
Expands the human readable part into a character array for checksumming.
convertBits()  : array<string|int, int>
Converts words of $fromBits bits to $toBits bits in size.
createChecksum()  : array<string|int, int>
verifyChecksum()  : bool
Verifies the checksum given $hrp and $convertedDataChars.
encode()  : string
decodeRaw()  : array<string|int, mixed>
decode()  : array<string|int, mixed>
Validates a bech32 string and returns [$hrp, $dataChars] if the conversion was successful. An exception is thrown on invalid data.
validateWitnessProgram()  : mixed
encodeSegwit()  : string
decodeSegwit()  : array<string|int, mixed>

Constants

CHARKEY_KEY

public mixed CHARKEY_KEY = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, 10, 17, 21, 20, 26, 30, 7, 5, -1, -1, -1, -1, -1, -1, -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1, -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1]

CHARSET

public mixed CHARSET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'

GENERATOR

public mixed GENERATOR = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3]

Functions

polyMod()

polyMod(array<string|int, int> $values, int $numValues) : int
Parameters
$values : array<string|int, int>
$numValues : int
Return values
int

hrpExpand()

Expands the human readable part into a character array for checksumming.

hrpExpand(string $hrp, int $hrpLen) : array<string|int, int>
Parameters
$hrp : string
$hrpLen : int
Return values
array<string|int, int>

convertBits()

Converts words of $fromBits bits to $toBits bits in size.

convertBits(array<string|int, int> $data, int $inLen, int $fromBits, int $toBits[, bool $pad = true ]) : array<string|int, int>
Parameters
$data : array<string|int, int>
  • character array of data to convert
$inLen : int
  • number of elements in array
$fromBits : int
  • word (bit count) size of provided data
$toBits : int
  • requested word size (bit count)
$pad : bool = true
  • whether to pad (only when encoding)
Tags
throws
Bech32Exception
Return values
array<string|int, int>

createChecksum()

createChecksum(string $hrp, array<string|int, int> $convertedDataChars) : array<string|int, int>
Parameters
$hrp : string
$convertedDataChars : array<string|int, int>
Return values
array<string|int, int>

verifyChecksum()

Verifies the checksum given $hrp and $convertedDataChars.

verifyChecksum(string $hrp, array<string|int, int> $convertedDataChars) : bool
Parameters
$hrp : string
$convertedDataChars : array<string|int, int>
Return values
bool

encode()

encode(string $hrp, array<string|int, mixed> $combinedDataChars) : string
Parameters
$hrp : string
$combinedDataChars : array<string|int, mixed>
Return values
string

decodeRaw()

decodeRaw(string $sBech) : array<string|int, mixed>
Parameters
$sBech : string
  • the bech32 encoded string
Tags
throws
Bech32Exception
Return values
array<string|int, mixed>
  • returns [$hrp, $dataChars]

decode()

Validates a bech32 string and returns [$hrp, $dataChars] if the conversion was successful. An exception is thrown on invalid data.

decode(string $sBech) : array<string|int, mixed>
Parameters
$sBech : string
  • the bech32 encoded string
Tags
throws
Bech32Exception
Return values
array<string|int, mixed>
  • returns [$hrp, $dataChars]

validateWitnessProgram()

validateWitnessProgram(int $version, string $program) : mixed
Parameters
$version : int
$program : string
Tags
throws
Bech32Exception

encodeSegwit()

encodeSegwit(string $hrp, int $version, string $program) : string
Parameters
$hrp : string
  • human readable part
$version : int
  • segwit script version
$program : string
  • segwit witness program
Tags
throws
Bech32Exception
Return values
string
  • the encoded address

decodeSegwit()

decodeSegwit(string $hrp, string $bech32) : array<string|int, mixed>
Parameters
$hrp : string
  • human readable part
$bech32 : string
  • Bech32 string to be decoded
Tags
throws
Bech32Exception
Return values
array<string|int, mixed>
  • [$version, $program]

        
On this page

Search results