bech32

package
v0.0.0-...-7c1506c Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2023 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. Doesn't do anything segwit specific.

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. It doesn't do any segwit specific encoding.

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 GetHRP

func GetHRP(adr string) (string, error)

Segwit addresses can't be used in Encode and Decode directly, because the witness version is special and doesn't get squashed. GetHRP gets the HRP without checking any validity.

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 SegWitAddressDecode

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

SegWitAddressDecode takes a segwit address and returns the pkscript that can go directly into the txout. (includes version byte and data push byte)

func SegWitAddressEncode

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

SegWitAddressEncode takes an hrp and data and gives back a segwit address. The data that goes in should be the full pkscript from the txout, including the version byte and the pushdata byte.

func SegWitV0Encode

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

SegWitV0Encode takes an hrp prefix string and a 20 or 32 byte witness program hash, and turns it into a version 0 address. (it puts the 0 and pushdata in for you.

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