base58

package module
Version: v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: MIT Imports: 2 Imported by: 64

README

base58-go

CI Status Go Report Card MIT License release pkg.go.dev

Base58 encoding/decoding package in Go

This is a Go language package for encoding and decoding base58 strings. This package supports multiple encodings, flickr, ripple and bitcoin.

Package Usage

package main

import (
	"fmt"
	"os"

	"github.com/itchyny/base58-go"
)

func main() {
	encoding := base58.FlickrEncoding // or RippleEncoding or BitcoinEncoding

	encoded, err := encoding.Encode([]byte("100"))
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	fmt.Println(string(encoded))

	decoded, err := encoding.Decode(encoded)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	fmt.Println(string(decoded))
}

base58 command

Homebrew
brew install itchyny/tap/base58
Build from source
go install github.com/itchyny/base58-go/cmd/base58@latest
Basic usage
 $ base58
100
2J
100000000
9QwvW
79228162514264337593543950336
5QchsBFApWPVxyp9C
^D
 $ base58 --decode
2J
100
9QwvW
100000000
5QchsBFApWPVxyp9C
79228162514264337593543950336
^D
 $ echo 100000000 | base58
9QwvW
 $ echo 9QwvW | base58 --decode
100000000
 $ echo 100000000 | base58 --encoding=bitcoin
9qXWw

Bug Tracker

Report bug at Issues・itchyny/base58-go - GitHub.

Author

itchyny (https://github.com/itchyny)

License

This software is released under the MIT License, see LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BitcoinEncoding = New([]byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"))

BitcoinEncoding is the encoding scheme used for Bitcoin addresses.

View Source
var FlickrEncoding = New([]byte("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"))

FlickrEncoding is the encoding scheme used for Flickr's short URLs.

View Source
var RippleEncoding = New([]byte("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"))

RippleEncoding is the encoding scheme used for Ripple addresses.

Functions

This section is empty.

Types

type Encoding

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

An Encoding is a radix 58 encoding/decoding scheme.

func New

func New(alphabet []byte) *Encoding

New creates a new base58 encoding.

func (*Encoding) Decode

func (enc *Encoding) Decode(src []byte) ([]byte, error)

Decode decodes the base58 encoded bytes.

func (*Encoding) DecodeUint64 added in v0.2.0

func (enc *Encoding) DecodeUint64(src []byte) (uint64, error)

DecodeUint64 decodes the base58 encoded bytes to an unsigned integer.

func (*Encoding) Encode

func (enc *Encoding) Encode(src []byte) ([]byte, error)

Encode encodes the number represented in the byte slice base 10.

func (*Encoding) EncodeUint64 added in v0.2.0

func (enc *Encoding) EncodeUint64(n uint64) []byte

EncodeUint64 encodes the unsigned integer.

func (*Encoding) UnmarshalFlag added in v0.0.2

func (enc *Encoding) UnmarshalFlag(value string) error

UnmarshalFlag implements flags.Unmarshaler

Source Files

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL