bech32m

package
v1.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2024 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

View Source
const ChecksumConst = int(0x2bc830a3)

ChecksumConst is a type that represents the currently defined bech32 checksum constants.

Variables

This section is empty.

Functions

func ConvertBits

func ConvertBits(data []byte, fromBits, toBits uint8, pad bool) ([]byte, error)

ConvertBits converts a byte slice where each byte is encoding fromBits bits, to a byte slice where each byte is encoding toBits bits.

func Decode

func Decode(bech string) (string, []byte, error)

Decode decodes a bech32 encoded string, returning the human-readable part and the data part excluding the checksum.

Note that the returned data is 5-bit (base32) encoded and the human-readable part will be lowercase.

func DecodeNoLimit

func DecodeNoLimit(bech string) (string, []byte, error)

DecodeNoLimit decodes a bech32 encoded string, returning the human-readable part and the data part excluding the checksum. This function does NOT validate against the BIP-173 maximum length allowed for bech32 strings.

Note that the returned data is 5-bit (base32) encoded and the human-readable part will be lowercase.

func DecodeToBase256

func DecodeToBase256(bech string) (string, []byte, error)

DecodeToBase256 decodes a bech32-encoded string into its associated human-readable part (HRP) and base32-encoded data, converts that data to a base256-encoded byte slice and returns it along with the lowercase HRP.

func DecodeToBase256WithTypeNoLimit

func DecodeToBase256WithTypeNoLimit(bech string) (string, byte, []byte, error)

DecodeToBase256WithTypeNoLimit decodes a bech32-encoded string into its associated human-readable part (HRP), type byte and base32-encoded data, converts that data to a base256-encoded byte slice.

This function does NOT validate against the BIP-173 maximum length allowed for bech32 strings.

func Encode

func Encode(hrp string, data []byte) (string, error)

Encode encodes a byte slice into a bech32 string with the given human-readable part (HRP). The HRP will be converted to lowercase if needed since mixed cased encodings are not permitted and lowercase is used for checksum purposes. Note that the bytes must each encode 5 bits (base32).

func EncodeFromBase256

func EncodeFromBase256(hrp string, data []byte) (string, error)

EncodeFromBase256 converts a base256-encoded byte slice into a base32-encoded byte slice and then encodes it into a bech32 string with the given human-readable part (HRP). The HRP will be converted to lowercase if needed since mixed cased encodings are not permitted and lowercase is used for checksum purposes.

func EncodeFromBase256WithType

func EncodeFromBase256WithType(hrp string, typ byte, data []byte) (string, error)

EncodeFromBase256WithType converts a base256-encoded byte slice into a base32-encoded byte slice and, concatenates the given type at the beginning and then encodes it into a bech32 string with the given human-readable part (HRP).

The HRP will be converted to lowercase if needed since mixed cased encodings are not permitted and lowercase is used for checksum purposes. The maximum size of type byte is 5 bits.

Types

type InvalidBitGroupsError added in v0.15.0

type InvalidBitGroupsError struct{}

InvalidBitGroupsError is returned when conversion is attempted between byte slices using bit-per-element of unsupported value.

func (InvalidBitGroupsError) Code added in v0.15.0

func (e InvalidBitGroupsError) Code() int

func (InvalidBitGroupsError) Error added in v0.15.0

func (e InvalidBitGroupsError) Error() string

type InvalidCharacterError added in v0.15.0

type InvalidCharacterError rune

InvalidCharacterError is returned when the bech32 string has a character outside the range of the supported charset.

func (InvalidCharacterError) Code added in v0.15.0

func (e InvalidCharacterError) Code() int

func (InvalidCharacterError) Error added in v0.15.0

func (e InvalidCharacterError) Error() string

type InvalidChecksumError added in v0.15.0

type InvalidChecksumError struct {
	Expected string
	Actual   string
}

InvalidChecksumError is returned when the extracted checksum of the string is different than what was expected.

func (InvalidChecksumError) Code added in v0.15.0

func (e InvalidChecksumError) Code() int

func (InvalidChecksumError) Error added in v0.15.0

func (e InvalidChecksumError) Error() string

type InvalidDataByteError added in v0.15.0

type InvalidDataByteError byte

InvalidDataByteError is returned when a byte outside the range required for conversion into a string was found.

func (InvalidDataByteError) Code added in v0.15.0

func (e InvalidDataByteError) Code() int

func (InvalidDataByteError) Error added in v0.15.0

func (e InvalidDataByteError) Error() string

type InvalidIncompleteGroupError added in v0.15.0

type InvalidIncompleteGroupError struct{}

InvalidIncompleteGroupError is returned when then byte slice used as input has data of wrong length.

func (InvalidIncompleteGroupError) Code added in v0.15.0

func (InvalidIncompleteGroupError) Error added in v0.15.0

type InvalidLengthError added in v0.15.0

type InvalidLengthError int

InvalidLengthError is returned when the bech32 string has an invalid length given the BIP-173 defined restrictions.

func (InvalidLengthError) Code added in v0.15.0

func (e InvalidLengthError) Code() int

func (InvalidLengthError) Error added in v0.15.0

func (e InvalidLengthError) Error() string

type InvalidSeparatorIndexError added in v0.15.0

type InvalidSeparatorIndexError int

InvalidSeparatorIndexError is returned when the separator character '1' is in an invalid position in the bech32 string.

func (InvalidSeparatorIndexError) Code added in v0.15.0

func (InvalidSeparatorIndexError) Error added in v0.15.0

type MixedCaseError added in v0.15.0

type MixedCaseError struct{}

MixedCaseError is returned when the bech32 string has both lower and uppercase characters.

func (MixedCaseError) Code added in v0.15.0

func (e MixedCaseError) Code() int

func (MixedCaseError) Error added in v0.15.0

func (e MixedCaseError) Error() string

type NonCharsetCharError added in v0.15.0

type NonCharsetCharError rune

NonCharsetCharError is returned when a character outside the specific bech32 charset is used in the string.

func (NonCharsetCharError) Code added in v0.15.0

func (e NonCharsetCharError) Code() int

func (NonCharsetCharError) Error added in v0.15.0

func (e NonCharsetCharError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL