Skip to main content

Class: Bech32Helper

Convert address to bech32.

Table of contents

Properties

Methods

Constructors

Properties

BECH32_DEFAULT_HRP_MAIN

Static BECH32_DEFAULT_HRP_MAIN: string = "iota"

The default human readable part of the bech32 addresses for mainnet, currently 'iota'.


BECH32_DEFAULT_HRP_DEV

Static BECH32_DEFAULT_HRP_DEV: string = "atoi"

The default human readable part of the bech32 addresses for devnet, currently 'atoi'.

Methods

toBech32

Static toBech32(addressType, addressBytes, humanReadablePart): string

Encode an address to bech32.

Parameters

NameTypeDescription
addressTypenumberThe address type to encode.
addressBytesUint8ArrayThe address bytes to encode.
humanReadablePartstringThe human readable part to use.

Returns

string

The array formated as hex.


fromBech32

Static fromBech32(bech32Text, humanReadablePart): undefined | {}

Decode an address from bech32.

Parameters

NameTypeDescription
bech32TextstringThe bech32 text to decode.
humanReadablePartstringThe human readable part to use.

Returns

undefined | {}

The address type and address bytes or undefined if it cannot be decoded.


addressFromBech32

Static addressFromBech32(bech32Address, humanReadablePart): AddressTypes

Decode an address from bech32.

Parameters

NameTypeDescription
bech32AddressstringThe bech32 address to decode.
humanReadablePartstringThe human readable part to use.

Returns

AddressTypes

The address type.


matches

Static matches(bech32Text, humanReadablePart): boolean

Does the provided string look like it might be an bech32 address with matching hrp.

Parameters

NameTypeDescription
bech32TextstringThe bech32 text to text.
humanReadablePartstringThe human readable part to match.

Returns

boolean

True if the passed address matches the pattern for a bech32 address.

Constructors

constructor

new Bech32Helper()