bech32

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: ISC, MIT Imports: 2 Imported by: 4

README

eagain.net/go/bech32 -- Human-friendly encoding for binary data

go get eagain.net/go/bech32

Package bech32 implements the "Bech32" encoding as specified in https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki

Note that Bech32 is not RFC 4648/3548, for that see encoding/base32. It is also not z-base-32, for that see github.com/tv42/zbase32. Compared to those, Bech32 adds a tag identifying type of stored data and a checksum. Bech32 was popularized by Bitcoin.

Command line utilities

Included are simple command-line utilities for encoding/decoding data. Example:

$ echo hello, world | bech32-encode greet
greet1dpjkcmr09ss8wmmjd3jq54mcuzl
$ bech32-decode greet1dpjkcmr09ss8wmmjd3jq54mcuzl
hello, world
$ printf '\x01binary!!!1\x00' | bech32-encode hckrspk
hckrspk1q93xjmnpwfujzgfpxyqqs8a2ax
$ bech32-decode hckrspk1q93xjmnpwfujzgfpxyqqs8a2ax | hexdump -C
00000000  01 62 69 6e 61 72 79 21  21 21 31 00              |.binary!!!1.|
0000000c

Origins

At the beginning of this project, the library was copied from filippo.io/age/internal/bech32 as of version v1.0.0-beta6, in order to make it available outside of the age project. For more information on age, see https://age-encryption.org/

It seems that this code was an improved and much cleaned up version of github.com/btcsuite/btcutil/bech32, that had internally maintained at Google until it was open sourced as part of age.

Documentation

Overview

Package bech32 is a modified version of the reference implementation of BIP173.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(s string) (hrp string, data []byte, err error)

Decode decodes a Bech32 string. If the string is uppercase, the HRP will be uppercase.

func Encode

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

Encode encodes the HRP and a bytes slice to Bech32. If the HRP is uppercase, the output will be uppercase.

Types

This section is empty.

Directories

Path Synopsis
cmd
bech32-decode
Command bech32-decode decodes bech32 from arguments or lines of stdin.
Command bech32-decode decodes bech32 from arguments or lines of stdin.
bech32-encode
Command bech32-encode encodes its standard input as bech32.
Command bech32-encode encodes its standard input as bech32.

Jump to

Keyboard shortcuts

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