Skip to main content

Class: Bech32

Class to help with Bech32 encoding/decoding. Based on reference implementation https://github.com/sipa/bech32/blob/master/ref/javascript/bech32.js.

Table of contents

Methods

Constructors

Methods

encode

Static encode(humanReadablePart, data): string

Encode the buffer.

Parameters

NameTypeDescription
humanReadablePartstringThe header.
dataUint8ArrayThe data to encode.

Returns

string

The encoded data.


encode5BitArray

Static encode5BitArray(humanReadablePart, data5Bit): string

Encode the 5 bit data buffer.

Parameters

NameTypeDescription
humanReadablePartstringThe header.
data5BitUint8ArrayThe data to encode.

Returns

string

The encoded data.


decode

Static decode(bech): undefined | {}

Decode a bech32 string.

Parameters

NameTypeDescription
bechstringThe text to decode.

Returns

undefined | {}

The decoded data or undefined if it could not be decoded.


decodeTo5BitArray

Static decodeTo5BitArray(bech): undefined | {}

Decode a bech32 string to 5 bit array.

Parameters

NameTypeDescription
bechstringThe text to decode.

Returns

undefined | {}

The decoded data or undefined if it could not be decoded.


to5Bit

Static to5Bit(bytes): Uint8Array

Convert the input bytes into 5 bit data.

Parameters

NameTypeDescription
bytesUint8ArrayThe bytes to convert.

Returns

Uint8Array

The data in 5 bit form.


from5Bit

Static from5Bit(fiveBit): Uint8Array

Convert the 5 bit data to 8 bit.

Parameters

NameTypeDescription
fiveBitUint8ArrayThe 5 bit data to convert.

Returns

Uint8Array

The 5 bit data converted to 8 bit.


matches

Static matches(humanReadablePart, bech32Text?): boolean

Does the given string match the bech32 pattern.

Parameters

NameTypeDescription
humanReadablePartstringThe human readable part.
bech32Text?stringThe text to test.

Returns

boolean

True if this is potentially a match.

Constructors

constructor

new Bech32()