bech32

package
v0.2.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteSquasher

func ByteSquasher(input []byte, inputWidth, outputWidth uint32) ([]byte, error)

ByteSquasher squashes full-width (8-bit) bytes into "squashed" 5-bit bytes, and vice versa. It can operate on other widths but in this package only goes 5 to 8 and back again. It can return an error if the squashed input you give it isn't actually squashed, or if there is padding (trailing q characters) when going from 5 to 8

func Bytes5to8

func Bytes5to8(input []byte) ([]byte, error)

Bytes5to8 goes from squashed bytes to full height bytes

func Bytes8to5

func Bytes8to5(input []byte) []byte

Bytes8to5 extends a byte slice into a longer, padded byte slice of 5-bit elements where the high 3 bits are all 0.

func CreateChecksum

func CreateChecksum(hrp string, data []byte) []byte

create checksum makes a 6-shortbyte checksum from the HRP and data parts

func Decode

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

Decode takes a bech32 encoded string and returns the hrp and the full-height data. Can error out for various reasons, mostly problems in the string given.

func DecodeSquashed

func DecodeSquashed(adr string) (string, []byte, error)

DecodeSquashed is the same as Decode, but will return squashed 5-bit high data.

func Encode

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

Encode takes regular bytes of data, and an hrp prefix, and returns the bech32 encoded string.

func EncodeSquashed

func EncodeSquashed(hrp string, data []byte) string

EncodeSquashed takes the hrp prefix, as well as byte data that has already been squashed to 5-bits high, and returns the bech32 encoded string. It does not return an error; if you give it non-squashed data it will return an empty string.

func HRPExpand

func HRPExpand(input string) []byte

HRPExpand turns the human redable part into 5bit-bytes for later processing

func PolyMod

func PolyMod(values []byte) uint32

PolyMod takes a byte slice and returns the 32-bit BCH checksum. Note that the input bytes to PolyMod need to be squashed to 5-bits tall before being used in this function. And this function will not error, but instead return an unusable checksum, if you give it full-height bytes.

func SquashedBytesToString

func SquashedBytesToString(input []byte) (string, error)

SquashedBytesToString swaps 5-bit bytes with a string of the corresponding letters

func StringToSquashedBytes

func StringToSquashedBytes(input string) ([]byte, error)

StringToSquashedBytes uses the inverseCharset to switch from the characters back to 5-bit squashed bytes.

func VerifyChecksum

func VerifyChecksum(hrp string, data []byte) bool

Types

This section is empty.

Jump to

Keyboard shortcuts

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