utils

package
v0.0.0-...-947961c Latest Latest
Warning

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

Go to latest
Published: May 16, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PublicKeyCompressedLength = 33

	// ErrInvalidPrivateKey is returned when a derived private key is invalid
	ErrInvalidPrivateKey = errors.New("Invalid private key")

	// ErrInvalidPublicKey is returned when a derived public key is invalid
	ErrInvalidPublicKey = errors.New("Invalid public key")
)
View Source
var Base58 = NewEncoding(bitcoinBase58Alphabet)
View Source
var (
	// ErrInvalidChecksum is returned when deserializing a key with an incorrect
	// checksum
	ErrInvalidChecksum = errors.New("Checksum doesn't match")
)

Functions

func AddChecksumToBytes

func AddChecksumToBytes(data []byte) ([]byte, error)

func AddPrivateKeys

func AddPrivateKeys(key1 []byte, key2 []byte) []byte

func AddPublicKeys

func AddPublicKeys(key1 []byte, key2 []byte) []byte

func B58AddressToHash160

func B58AddressToHash160(address string) (hash160 []byte, addrType int, err error)

func Checksum

func Checksum(data []byte) ([]byte, error)

func Hash160

func Hash160(data []byte) ([]byte, error)

func Hash160ToB58Address

func Hash160ToB58Address(hash160 []byte, addrType int) (string, error)

func HashDoubleSha256

func HashDoubleSha256(data []byte) ([]byte, error)

func HashRipeMD160

func HashRipeMD160(data []byte) ([]byte, error)

func HashSha256

func HashSha256(data []byte) ([]byte, error)

func Int64ToBytes

func Int64ToBytes(i int64) []byte

func IsB58Address

func IsB58Address(address string) bool

func PublicKeyForPrivateKey

func PublicKeyForPrivateKey(key []byte) []byte

func Uint16Bytes

func Uint16Bytes(i uint16) []byte

func Uint32Bytes

func Uint32Bytes(i uint32) []byte

func ValidateChecksum

func ValidateChecksum(data []byte) ([]byte, error)

func ValidateChildPublicKey

func ValidateChildPublicKey(key []byte) error

func ValidatePrivateKey

func ValidatePrivateKey(key []byte) error

func WIFDecode

func WIFDecode(key string) (prefix int, secret []byte, compressed bool, err error)

func WIFEncode

func WIFEncode(prefix int, secret []byte, compressed bool) (string, error)

Types

type Encoding

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

Encoding represents a given base-N encoding.

func NewEncoding

func NewEncoding(alphabet string) *Encoding

NewEncoding creates a new base-N representation from the given alphabet. Panics if the alphabet is not unique. Only ASCII characters are supported.

func (*Encoding) Base

func (enc *Encoding) Base() int

Base returns the number base of the encoding.

func (*Encoding) DecodeString

func (enc *Encoding) DecodeString(s string) ([]byte, error)

DecodeString returns the bytes for the given base-encoded string.

func (*Encoding) DecodeStringN

func (enc *Encoding) DecodeStringN(s string, n int) ([]byte, error)

DecodeStringN returns N bytes for the given base-encoded string. Use this method to ensure the value is left-padded with zeroes.

func (*Encoding) EncodeToString

func (enc *Encoding) EncodeToString(b []byte) string

EncodeToString returns the base-encoded string representation of the given bytes.

func (*Encoding) MustRandom

func (enc *Encoding) MustRandom(n int) string

MustRandom returns the base-encoded representation of n random bytes, panicking in the unlikely event of a read error from the random source.

func (*Encoding) Random

func (enc *Encoding) Random(n int) (string, error)

Random returns the base-encoded representation of n random bytes.

Jump to

Keyboard shortcuts

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