base58

package
v0.0.0-...-78ae864 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2014 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Base58 is a group of binary-to-text encoding schemes used to represent large integers as alphanumeric text. It is similar to Base64 but has been modified to avoid both non-alphanumeric characters and letters which might look ambiguous when printed. It is therefore designed for human users who manually enter the data, copying from some visual source, but also allows easy copy and paste because a double-click will usually select the whole string.

Compared to Base64, the following letters have been omitted from the alphabet: 0 (zero), O (capital o), I (capital i) and l (lower case L) as well as the non-alphanumeric characters + (plus) and / (slash). In contrast to Base64, the digits of the encoding don't line up well with byte boundaries of the original data. For this reason, the method is well-suited to encode large integers, but not designed to encode longer portions of binary data. The actual order of letters in the alphabet depends on the application, which is the reason why the term “Base58” alone is not enough to fully describe the format.

base58 returns encoded text suitable for use with Bitcoin. Bitcoin compatible base58 does not pad like fixed width base58. As a result, the size of the returned slice can be different for the same sized input.

Index

Examples

Constants

View Source
const Radix = len(base58table)

The radix of the base58 encoding system.

Variables

View Source
var BitsPerDigit = math.Log2(float64(Radix))

Bits of entropy per base 58 digit.

View Source
var ErrInvalid = errors.New("encoding/base58: invalid character found")

Functions

func Check

func Check(h []byte) string

Base58Check accepts a byte string and returns base58 encoded verification string as defined: https://en.bitcoin.it/wiki/Base58Check_encoding#Creating_a_Base58Check_string

func Decode

func Decode(src []byte) ([]byte, int, error)

Decode decodes src base10 string and returns the base58 encoded string and size of the result.

Example (Bitaddress)
addr := []byte("1PbyRQXKNCwcmn43ZpJ4pxFEAvnG8iAc6J")
fmt.Printf("Bitcoin addresses are %d characters long\n", len(addr))
decoded, len, err := Decode(addr)
if err != nil {
	fmt.Println(err)
}
fmt.Printf("Length of byte slice: %d\n", len)
fmt.Printf("address in hex: %x\n", decoded)
fmt.Printf("Byte slice: %v\n", decoded)
Output:

Bitcoin addresses are 34 characters long
Length of byte slice: 25
address in hex: 00f7f001f4f3c2e3ea60440f4e3f97d9dd5266345d234d30b7
Byte slice: [0 247 240 1 244 243 194 227 234 96 68 15 78 63 151 217 221 82 102 52 93 35 77 48 183]

func DecodeString

func DecodeString(s string) ([]byte, error)

DecodeString returns the bytes represented by the base58 string s

func DecodedLen

func DecodedLen()

func DoubleSha256

func DoubleSha256(b []byte) []byte

DoubleSha256 wraps calling Sha256 twice

func Encode

func Encode(src []byte) ([]byte, int)

Encode creates Bitcoin compatible Base58 encoded strings from a byte slice. The length is variable based on same sized input slice.

Example (Hex)
// Decode hex prior to passing it to Encode
h := []byte("bf4f89001e670274dd")
ten := make([]byte, hex.DecodedLen(len(h)))
hex.Decode(ten, h)
fmt.Printf("base10: %d\n", ten)
fmt.Printf("hex: %x\n", ten)

fifty, len := Encode(ten)
fmt.Printf("len: %d text: %s\n", len, fifty)
Output:

base10: [191 79 137 0 30 103 2 116 221]
hex: bf4f89001e670274dd
len: 13 text: 3SEo3LWLoPntC

func EncodeToString

func EncodeToString(src []byte) string

EncodeToString returns a string from a byte slice.

func EncodedLen

func EncodedLen()

func MaxEncodedLen

func MaxEncodedLen(b []byte) int

Base58MaxEncodedLen returns the maximum possible length of a base58 encoding. This number may be larger than the encoded slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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