crypto

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: Apache-2.0, MIT Imports: 16 Imported by: 9

Documentation

Index

Constants

View Source
const (
	SigTypeSecp256k1 = crypto.SigTypeSecp256k1
	SigTypeBLS       = crypto.SigTypeBLS
)
View Source
const PrivateKeyBytes = 32

PrivateKeyBytes is the size of a serialized private key.

Variables

This section is empty.

Functions

func EcRecover

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

EcRecover recovers the public key from a message, signature pair.

func PublicKeyForSecpSecretKey

func PublicKeyForSecpSecretKey(sk []byte) []byte

PublicKeyForSecpSecretKey returns the public key for this private key.

func SignBLS

func SignBLS(sk, msg []byte) ([]byte, error)

SignBLS signs the given message with BLS.

func SignSecp

func SignSecp(sk, msg []byte) ([]byte, error)

SignSecp signs the given message using secp256k1 based cryptography, which must be 32 bytes long.

func ValidateBlsSignature

func ValidateBlsSignature(data []byte, addr address.Address, signature []byte) error

func ValidateSecpSignature

func ValidateSecpSignature(data []byte, addr address.Address, signature []byte) error

func ValidateSignature

func ValidateSignature(data []byte, addr address.Address, sig Signature) error

ValidateSignature cryptographically verifies that 'sig' is the signed hash of 'data' with the public key belonging to `addr`.

func VerifyBLS

func VerifyBLS(pubKey, msg, signature []byte) bool

VerifyBLS checks the given signature is valid using BLS cryptography.

func VerifyBLSAggregate

func VerifyBLSAggregate(pubKeys, msgs [][]byte, signature []byte) bool

VerifyBLSAggregate checks the given signature is a valid aggregate signature over all messages and public keys

func VerifySecp

func VerifySecp(pk, msg, signature []byte) bool

VerifySecp checks the given signature is a secp256k1 signature and returns true if it is valid.

Types

type KeyInfo

type KeyInfo struct {
	// Private key.
	PrivateKey *memguard.Enclave `json:"privateKey"`
	// Cryptographic system used to generate private key.
	SigType SigType `json:"type"`
}

KeyInfo is a key and its type used for signing.

func NewBLSKeyFromSeed

func NewBLSKeyFromSeed(seed io.Reader) (KeyInfo, error)

func NewSecpKeyFromSeed

func NewSecpKeyFromSeed(seed io.Reader) (KeyInfo, error)

NewSecpKeyFromSeed generates a new key from the given reader.

func (*KeyInfo) Address

func (ki *KeyInfo) Address() (address.Address, error)

Address returns the address for this keyinfo

func (*KeyInfo) Equals

func (ki *KeyInfo) Equals(other *KeyInfo) bool

Equals returns true if the KeyInfo is equal to other.

func (*KeyInfo) Key

func (ki *KeyInfo) Key() []byte

Key returns the private key of KeyInfo This method makes the key escape from memguard's protection, so use caution

func (KeyInfo) MarshalJSON

func (ki KeyInfo) MarshalJSON() ([]byte, error)

func (*KeyInfo) PublicKey

func (ki *KeyInfo) PublicKey() ([]byte, error)

Returns the public key part as uncompressed bytes.

func (*KeyInfo) SetPrivateKey added in v0.9.7

func (ki *KeyInfo) SetPrivateKey(privateKey []byte)

func (*KeyInfo) Type

func (ki *KeyInfo) Type() SigType

Type returns the type of curve used to generate the private key

func (*KeyInfo) UnmarshalJSON

func (ki *KeyInfo) UnmarshalJSON(data []byte) error

func (*KeyInfo) UsePrivateKey added in v0.9.7

func (ki *KeyInfo) UsePrivateKey(f func([]byte) error) error

type SigType

type SigType = crypto.SigType

type Signature

type Signature = crypto.Signature

func Sign

func Sign(data []byte, secretKey []byte, sigtype SigType) (*Signature, error)

Directories

Path Synopsis
bls

Jump to

Keyboard shortcuts

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