crypto

package
v0.1.8-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2019 License: GPL-3.0 Imports: 12 Imported by: 11

Documentation

Overview

Package crypto provides key and address creation functions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTxVerificationFailed means signature verification failed
	ErrTxVerificationFailed = fmt.Errorf("transaction verification failed")

	// ErrBlockVerificationFailed means signature verification failed
	ErrBlockVerificationFailed = fmt.Errorf("block verification failed")
)
View Source
var AddressVersion byte = 92

AddressVersion is the base58 encode version adopted

View Source
var PrivateKeyVersion byte = 94

PrivateKeyVersion is the base58 encode version adopted for private keys

View Source
var PublicKeyVersion byte = 93

PublicKeyVersion is the base58 encode version adopted for public keys

Functions

func IsValidAddr

func IsValidAddr(addr string) error

IsValidAddr checks whether an address is valid

func IsValidPrivKey

func IsValidPrivKey(privKey string) error

IsValidPrivKey checks whether a private key is valid

func IsValidPubKey

func IsValidPubKey(pubKey string) error

IsValidPubKey checks whether a public key is valid

Types

type Key

type Key struct {
	Meta map[string]interface{}
	// contains filtered or unexported fields
}

Key represents an address

func NewKey

func NewKey(seed *int64) (*Key, error)

NewKey creates a new key

func NewKeyFromIntSeed

func NewKeyFromIntSeed(seed int) *Key

NewKeyFromIntSeed is like NewKey but accepts seed of type Int and casts to Int64 Error is not returned. Intended to be used in test

func NewKeyFromPrivKey

func NewKeyFromPrivKey(sk *PrivKey) *Key

NewKeyFromPrivKey creates a new address from a private key

func (*Key) Addr

func (k *Key) Addr() util.String

Addr returns the address corresponding to the public key

func (*Key) PeerID

func (k *Key) PeerID() string

PeerID returns the IPFS compatible peer ID for the corresponding public key

func (*Key) PrivKey

func (k *Key) PrivKey() *PrivKey

PrivKey returns the private key

func (*Key) PubKey

func (k *Key) PubKey() *PubKey

PubKey returns the public key

type PrivKey

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

PrivKey represents a private key

func PrivKeyFromBase58

func PrivKeyFromBase58(pk string) (*PrivKey, error)

PrivKeyFromBase58 decodes a base58 encoded private key

func (*PrivKey) Base58

func (p *PrivKey) Base58() string

Base58 returns the public key in base58 encoding

func (*PrivKey) Bytes

func (p *PrivKey) Bytes() ([]byte, error)

Bytes returns the byte equivalent of the public key

func (*PrivKey) Marshal

func (p *PrivKey) Marshal() ([]byte, error)

Marshal encodes the private key using protocol buffer

func (*PrivKey) Sign

func (p *PrivKey) Sign(data []byte) ([]byte, error)

Sign signs a message

type PubKey

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

PubKey represents a public key

func PubKeyFromBase58

func PubKeyFromBase58(pk string) (*PubKey, error)

PubKeyFromBase58 decodes a base58 encoded public key

func (*PubKey) Addr

func (p *PubKey) Addr() util.String

Addr computes an address from the public key

func (*PubKey) Base58

func (p *PubKey) Base58() string

Base58 returns the public key in base58 encoding

func (*PubKey) Bytes

func (p *PubKey) Bytes() ([]byte, error)

Bytes returns the byte equivalent of the public key

func (*PubKey) Hex

func (p *PubKey) Hex() string

Hex returns the public key in hex encoding

func (*PubKey) Verify

func (p *PubKey) Verify(data, sig []byte) (bool, error)

Verify verifies a signature

Jump to

Keyboard shortcuts

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