base58

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: MIT Imports: 2 Imported by: 5

README

GoDoc

Modified implementation based on github.com/mr-tron/base58 itself based on https://github.com/trezor/trezor-crypto/blob/master/base58.c

It's nice to have a fast base58 implementation but do we really need to have the slow version in the same lib too?

Usage

// to decode some base58 string
dec, err := base58.Bitcoin.Decode(in)
if err != nil {
    // handle err
}
// or, to encode:
enc := base58.Bitcoin.Encode(dec)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Bitcoin = NewEncoding("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
	Flickr  = NewEncoding("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ")
)
View Source
var (
	ErrZeroLength = errors.New("base58: cannot decode zero length string")
	ErrNonAscii   = errors.New("base58: cannot decode non-ASCII input")
	ErrBadDigit   = errors.New("base58: cannot decode unsupported digit")
)

Functions

func EncodedLen added in v1.0.2

func EncodedLen(bin []byte) (int, int)

EncodedLen returns the encoded len for a given buffer, checking it for initial zeroes. It can be higher than needed.

func EncodedMaxLen added in v1.0.2

func EncodedMaxLen(ln int) int

EncodedMaxLen return the maximum encoded len for an input of ln bytes. If it starts with zeroes the actual len will be shorter

Types

type Encoding

type Encoding struct {
	// contains filtered or unexported fields
}

func NewEncoding

func NewEncoding(s string) *Encoding

NewEncoding returns a encoding structure initialized for decoding/encoding using the passed parameter

It panics if the passed string is not 58 bytes long or isn't valid ASCII.

func (*Encoding) Decode

func (e *Encoding) Decode(str string) ([]byte, error)

Decode will decode the provided string using the current encoding and return a byte array of the value, or an error if the input was not valid

func (*Encoding) Encode

func (e *Encoding) Encode(bin []byte) string

Encode will encode the provided byte array into a base58 encoded string using the current encoding.

func (*Encoding) EncodeTo added in v1.0.2

func (e *Encoding) EncodeTo(dst, src []byte) []byte

EncodeTo will encoded the provided byte array to the given buffer if it is large enough, or allocate a new one if not.

Jump to

Keyboard shortcuts

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