bech32

package
v0.0.2-0...-1c7e8a7 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2021 License: Unlicense Imports: 4 Imported by: 0

README

bech32

ISC License GoDoc

Package bech32 provides a Go implementation of the bech32 format specified in BIP 173. Test vectors from BIP 173 are added to ensure compatibility with the BIP.

Installation and Updating

$ go get -u github.com/l0k18/pod/btcutil/bech32

Examples

License

Package bech32 is licensed under the copyfree ISC License.

Documentation

Overview

Package bech32 provides a Go implementation of the bech32 format specified in BIP 173.

Bech32 strings consist of a human-readable part (hrp), followed by the separator 1, then a checksummed data part encoded using the 32 characters "qpzry9x8gf2tvdw0s3jn54khce6mua7l". More info: https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(err error) bool

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 Debug

func Debug(a ...interface{})

func Debugc

func Debugc(fn func() string)

func Debugf

func Debugf(format string, a ...interface{})

func Debugs

func Debugs(a interface{})

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.

Example

This example demonstrates how to decode a bech32 encoded string.

package main

import (
	"encoding/hex"
	"fmt"

	"github.com/l0k18/pod/pkg/coding/bech32"
)

func main() {
	encoded := "bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx"
	hrp, decoded, err := bech32.Decode(encoded)
	if err != nil {
		bech32.Error("Error:", err)
	}
	// Show the decoded data.
	fmt.Println("Decoded human-readable part:", hrp)
	fmt.Println("Decoded Data:", hex.EncodeToString(decoded))
}
Output:

Decoded human-readable part: bc
Decoded Data: 010e140f070d1a001912060b0d081504140311021d030c1d03040f1814060e1e160e140f070d1a001912060b0d081504140311021d030c1d03040f1814060e1e16

func Encode

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

Encode encodes a byte slice into a bech32 string with the human-readable part hrb. Note that the bytes must each encode 5 bits (base32).

Example

This example demonstrates how to encode data into a bech32 string.

package main

import (
	"fmt"

	"github.com/l0k18/pod/pkg/coding/bech32"
)

func main() {
	data := []byte("Test data")
	// Convert test data to base32:
	conv, err := bech32.ConvertBits(data, 8, 5, true)
	if err != nil {
		bech32.Error("Error:", err)
	}
	encoded, err := bech32.Encode("customHrp!11111q", conv)
	if err != nil {
		bech32.Error("Error:", err)
	}
	// Show the encoded data.
	fmt.Println("Encoded Data:", encoded)
}
Output:

Encoded Data: customHrp!11111q123jhxapqv3shgcgumastr

func Error

func Error(a ...interface{})

func Errorc

func Errorc(fn func() string)

func Errorf

func Errorf(format string, a ...interface{})

func Errors

func Errors(a interface{})

func Fatal

func Fatal(a ...interface{})

func Fatalc

func Fatalc(fn func() string)

func Fatalf

func Fatalf(format string, a ...interface{})

func Fatals

func Fatals(a interface{})

func Info

func Info(a ...interface{})

func Infoc

func Infoc(fn func() string)

func Infof

func Infof(format string, a ...interface{})

func Infos

func Infos(a interface{})

func Trace

func Trace(a ...interface{})

func Tracec

func Tracec(fn func() string)

func Tracef

func Tracef(format string, a ...interface{})

func Traces

func Traces(a interface{})

func Warn

func Warn(a ...interface{})

func Warnc

func Warnc(fn func() string)

func Warnf

func Warnf(format string, a ...interface{})

func Warns

func Warns(a interface{})

Types

This section is empty.

Jump to

Keyboard shortcuts

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