secp256k1

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2019 License: LGPL-3.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// EcdsaPrivateKeyLength private key length
	EcdsaPrivateKeyLength = 32
)

Variables

View Source
var (
	// ErrInvalidMsgLen invalid message length
	ErrInvalidMsgLen = errors.New("invalid message length, need 32 bytes")

	// ErrGetPublicKeyFailed private key to public failed
	ErrGetPublicKeyFailed = errors.New("private key to public failed")

	// ErrInvalidSignature invalid signature length
	ErrInvalidSignature = errors.New("invalid signature")

	// ErrInvalidPrivateKey invalid private key
	ErrInvalidPrivateKey = errors.New("invalid private key")

	// ErrInvalidPublicKey invalid public key
	ErrInvalidPublicKey = errors.New("invalid public key")

	// ErrSignFailed sign failed
	ErrSignFailed = errors.New("sign failed")

	// ErrRecoverFailed recover failed
	ErrRecoverFailed = errors.New("recovery failed")
)

Functions

func FromECDSAPrivateKey

func FromECDSAPrivateKey(priv *ecdsa.PrivateKey) ([]byte, error)

FromECDSAPrivateKey exports a private key into a binary dump.

func FromECDSAPublicKey

func FromECDSAPublicKey(pub *ecdsa.PublicKey) ([]byte, error)

FromECDSAPublicKey exports a public key into a binary dump.

func GetPublicKey added in v1.0.1

func GetPublicKey(seckey []byte) ([]byte, error)

GetPublicKey private key to public key

func HexToECDSAPrivateKey

func HexToECDSAPrivateKey(hexkey string) (*ecdsa.PrivateKey, error)

HexToECDSAPrivateKey parses a secp256k1 private key.

func NewECDSAPrivateKey

func NewECDSAPrivateKey() (*ecdsa.PrivateKey, error)

NewECDSAPrivateKey generate a ecdsa private key

func NewSeckey added in v1.0.1

func NewSeckey() []byte

NewSeckey generate a ecdsa private key by secp256k1

func RecoverECDSAPublicKey

func RecoverECDSAPublicKey(msg []byte, signature []byte) ([]byte, error)

RecoverECDSAPublicKey recover verifies the compact signature "signature" of "hash"

func S256

func S256() elliptic.Curve

S256 returns an instance of the secp256k1 curve.

func SeckeyVerify added in v1.0.0

func SeckeyVerify(seckey []byte) bool

SeckeyVerify check private is ok for secp256k1

func Sign

func Sign(msg []byte, seckey []byte) ([]byte, error)

Sign sign hash with private key

func ToECDSAPrivateKey

func ToECDSAPrivateKey(d []byte) (*ecdsa.PrivateKey, error)

ToECDSAPrivateKey creates a private key with the given data value.

func ToECDSAPublicKey

func ToECDSAPublicKey(pub []byte) (*ecdsa.PublicKey, error)

ToECDSAPublicKey creates a public key with the given data value.

func Verify

func Verify(msg []byte, signature []byte, pub []byte) (bool, error)

Verify verify with public key

Types

type PrivateKey

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

PrivateKey ecdsa privatekey

func GeneratePrivateKey

func GeneratePrivateKey() *PrivateKey

GeneratePrivateKey generate a new private key

func (*PrivateKey) Algorithm

func (k *PrivateKey) Algorithm() keystore.Algorithm

Algorithm algorithm name

func (*PrivateKey) Clear

func (k *PrivateKey) Clear()

Clear clear key content

func (*PrivateKey) Decode

func (k *PrivateKey) Decode(data []byte) error

Decode decode data to key

func (*PrivateKey) Encoded

func (k *PrivateKey) Encoded() ([]byte, error)

Encoded encoded to byte

func (*PrivateKey) PublicKey

func (k *PrivateKey) PublicKey() keystore.PublicKey

PublicKey returns publickey

func (*PrivateKey) Sign

func (k *PrivateKey) Sign(hash []byte) ([]byte, error)

Sign sign hash with privatekey

type PublicKey

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

PublicKey ecdsa publickey

func NewPublicKey

func NewPublicKey(pub []byte) *PublicKey

NewPublicKey generate PublicKey

func (*PublicKey) Algorithm

func (k *PublicKey) Algorithm() keystore.Algorithm

Algorithm algorithm name

func (*PublicKey) Clear

func (k *PublicKey) Clear()

Clear clear key content

func (*PublicKey) Decode

func (k *PublicKey) Decode(data []byte) error

Decode decode data to key

func (*PublicKey) Encoded

func (k *PublicKey) Encoded() ([]byte, error)

Encoded encoded to byte

func (*PublicKey) Verify

func (k *PublicKey) Verify(hash []byte, signature []byte) (bool, error)

Verify verify ecdsa publickey

type Signature

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

Signature signature ecdsa

func (*Signature) Algorithm

func (s *Signature) Algorithm() keystore.Algorithm

Algorithm secp256k1 algorithm

func (*Signature) InitSign

func (s *Signature) InitSign(priv keystore.PrivateKey) error

InitSign ecdsa init sign

func (*Signature) InitVerify

func (s *Signature) InitVerify(pub keystore.PublicKey) error

InitVerify ecdsa verify init

func (*Signature) RecoverPublic

func (s *Signature) RecoverPublic(data []byte, signature []byte) (keystore.PublicKey, error)

RecoverPublic returns a public key

func (*Signature) Sign

func (s *Signature) Sign(data []byte) (out []byte, err error)

Sign ecdsa sign

func (*Signature) Verify

func (s *Signature) Verify(data []byte, signature []byte) (bool, error)

Verify ecdsa verify

Directories

Path Synopsis
vrf

Jump to

Keyboard shortcuts

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