based32

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: Unlicense Imports: 7 Imported by: 1

README

based32

An implementation of a generic encoding system for human readable transcription purposes, as usually found in cryptocurrencies to put addresses and transaction hashes into a form that humans can easily and reliably write down and read back, with minimal chance of error.

It uses the base32 character set used in Bech32, but differs from Bech32 in that it is not solely targeted at the purpose of cryptocurrency addresses, keys and transaction identifiers, or, more precisely, that it is written to enable the use for any length (though not unlimited length, due to human patience and attention limitations) for anything from 32 bit binary codes up to 512 bits or thereabouts.

In order to achieve this, it works around the limitation of the standard Go base32 codec, available in the standard library, of needing the values to be in 40 bit chunks (5 bytes) which creates 8 character long segments each representing 5 bits of data, and the ugliness of padding, by varying the length of the check value to act in a second purpose as also the padding.

It therefore requires a prefix noting the length of the check bytes at the end of the code, which is never more than 3 bytes, so this allows the first base32 cipher to be omitted and readded upon decoding.

This is a part of an introductory programming tutorial/workshop to teach Go programming, as well as all the accessory parts of the process including documentation, code style, and project structuring, the details of the build system, and so on.

Documentation

Overview

Package based32 provides a simplified variant of the standard Bech32 human readable binary codec

This codec simplifies the padding algorithm compared to the Bech32 standard BIP 0173 by performing all of the check validation with the decoded bits instead of separating the pads of each segment.

The format will be entirely created by the use of the standard library base32, which may or may not result in the same thing (we are teaching Go here, not cryptocurrency, and the extra rules used by the Bech32 standard complicate this tutorial unnecessarily - and, Go Uber Alles :)

Index

Constants

This section is empty.

Variables

View Source
var Codec = makeCodec(
	"Base32Check",
	charset,
	"QNTRL",
)

Codec provides the encoder/decoder implementation created by makeCodec.

This variable is sometimes called a "Singleton" in other languages, and in Go it is a thing that should be avoided unless the value is not a constant and an initialization process is required.

Variable declarations like this are executed before init() functions and are for cases such as this, as the import of this package means the programmer intends to use this codec, usually, as otherwise they would be creating a new implementation from the struct type or for the interface.

In general, an init() function is better avoided, and singletons also, better avoided, unless it makes sense in the context of the package as this is this initialization adds to startup delay for an application, so consider carefully before using these or init().

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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