base58

package
v0.0.0-...-4398682 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2016 License: ISC Imports: 3 Imported by: 0

README

base58

[Build Status] (https://travis-ci.org/btcsuite/btcutil)

Package base58 provides an API for encoding and decoding to and from the modified base58 encoding. It also provides an API to do Base58Check encoding, as described here.

A comprehensive suite of tests is provided to ensure proper functionality. Package base58 is licensed under the copyfree ISC license.

Documentation

[GoDoc] (http://godoc.org/github.com/btcsuite/btcutil/base58)

Full go doc style documentation for the project can be viewed online without installing this package by using the GoDoc site here: http://godoc.org/github.com/btcsuite/btcutil/base58

You can also view the documentation locally once the package is installed with the godoc tool by running godoc -http=":6060" and pointing your browser to http://localhost:6060/pkg/github.com/btcsuite/btcutil/base58

Installation

$ go get github.com/btcsuite/btcutil/base58

Examples

License

Package base58 is licensed under the copyfree ISC License.

Documentation

Overview

Package base58 provides an API for working with modified base58 and Base58Check encodings.

Modified Base58 Encoding

Standard base58 encoding is similar to standard base64 encoding except, as the name implies, it uses a 58 character alphabet which results in an alphanumeric string and allows some characters which are problematic for humans to be excluded. Due to this, there can be various base58 alphabets.

The modified base58 alphabet used by Bitcoin, and hence this package, omits the 0, O, I, and l characters that look the same in many fonts and are therefore hard to humans to distinguish.

Base58Check Encoding Scheme

The Base58Check encoding scheme is primarily used for Bitcoin addresses at the time of this writing, however it can be used to generically encode arbitrary byte arrays into human-readable strings along with a version byte that can be used to differentiate the same payload. For Bitcoin addresses, the extra version is used to differentiate the network of otherwise identical public keys which helps prevent using an address intended for one network on another.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrChecksum = errors.New("checksum error")

ErrChecksum indicates that the checksum of a check-encoded string does not verify against the checksum.

View Source
var ErrInvalidFormat = errors.New("invalid format: version and/or checksum bytes missing")

ErrInvalidFormat indicates that the check-encoded string has an invalid format.

Functions

func CheckDecodeWithOneVersionByte

func CheckDecodeWithOneVersionByte(input string) (result []byte, version byte, err error)

CheckDecode decodes a string that was encoded with CheckEncode and verifies the checksum.

func CheckDecodeWithTwoVersionBytes

func CheckDecodeWithTwoVersionBytes(input string) (result []byte, v1 byte, v2 byte, err error)

CheckDecode decodes a string that was encoded with CheckEncode and verifies the checksum.

func CheckEncode

func CheckEncode(input []byte, version byte) string

CheckEncode prepends a version byte and appends a four byte checksum. func CheckEncode(input []byte, version byte) string { func CheckEncode(input []byte) string {

Example

This example demonstrates how to encode data using the Base58Check encoding scheme.

package main

import (
	"fmt"

	"github.com/FactomProject/btcutil/base58"
)

func main() {
	// Encode example data with the Base58Check encoding scheme.
	data := []byte("Test data")
	encoded := base58.CheckEncode(data, 0)

	// Show the encoded data.
	fmt.Println("Encoded Data:", encoded)

}
Output:

Encoded Data: 182iP79GRURMp7oMHDU

func CheckEncodeWithVersionBytes

func CheckEncodeWithVersionBytes(input []byte, b1, b2 byte) string

func Decode

func Decode(b string) []byte

Decode decodes a modified base58 string to a byte slice.

Example

This example demonstrates how to decode modified base58 encoded data.

package main

import (
	"fmt"

	"github.com/FactomProject/btcutil/base58"
)

func main() {
	// Decode example modified base58 encoded data.
	encoded := "25JnwSn7XKfNQ"
	decoded := base58.Decode(encoded)

	// Show the decoded data.
	fmt.Println("Decoded Data:", string(decoded))

}
Output:

Decoded Data: Test data

func Encode

func Encode(b []byte) string

Encode encodes a byte slice to a modified base58 string.

Example

This example demonstrates how to encode data using the modified base58 encoding scheme.

package main

import (
	"fmt"

	"github.com/FactomProject/btcutil/base58"
)

func main() {
	// Encode example data with the modified base58 encoding scheme.
	data := []byte("Test data")
	encoded := base58.Encode(data)

	// Show the encoded data.
	fmt.Println("Encoded Data:", encoded)

}
Output:

Encoded Data: 25JnwSn7XKfNQ

Types

This section is empty.

Jump to

Keyboard shortcuts

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