Documentation ¶
Index ¶
- func ByteSquasher(input []byte, inputWidth, outputWidth uint32) ([]byte, error)
- func Bytes5to8(input []byte) ([]byte, error)
- func Bytes8to5(input []byte) []byte
- func CreateChecksum(hrp string, data []byte) []byte
- func Decode(adr string) (string, []byte, error)
- func DecodeSquashed(adr string) (string, []byte, error)
- func Encode(hrp string, data []byte) string
- func EncodeSquashed(hrp string, data []byte) string
- func GetHRP(adr string) (string, error)
- func HRPExpand(input string) []byte
- func PolyMod(values []byte) uint32
- func SegWitAddressDecode(adr string) ([]byte, error)
- func SegWitAddressEncode(hrp string, data []byte) (string, error)
- func SegWitV0Encode(hrp string, data []byte) (string, error)
- func SquashedBytesToString(input []byte) (string, error)
- func StringToSquashedBytes(input string) ([]byte, error)
- func VerifyChecksum(hrp string, data []byte) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteSquasher ¶
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 Bytes8to5 ¶
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 ¶
create checksum makes a 6-shortbyte checksum from the HRP and data parts
func Decode ¶
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 ¶
DecodeSquashed is the same as Decode, but will return squashed 5-bit high data.
func Encode ¶
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 ¶
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 ¶
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 PolyMod ¶
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 ¶
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 ¶
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 ¶
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 ¶
SquashedBytesToString swaps 5-bit bytes with a string of the corresponding letters
func StringToSquashedBytes ¶
StringToSquashedBytes uses the inverseCharset to switch from the characters back to 5-bit squashed bytes.
func VerifyChecksum ¶
Types ¶
This section is empty.