crypto

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2022 License: Apache-2.0, MIT Imports: 9 Imported by: 9

Documentation

Index

Constants

View Source
const (
	SigTypeSecp256k1 = crypto.SigTypeSecp256k1
	SigTypeBLS       = crypto.SigTypeBLS
)
View Source
const (
	BLSSignatureBytes = 96
)

Variables

This section is empty.

Functions

func Generate added in v1.0.1

func Generate(sigType crypto.SigType) ([]byte, error)

Generate generates private key of given type

func RegisterSignature added in v1.0.1

func RegisterSignature(typ crypto.SigType, vs SigShim)

RegisterSignature should be only used during init

func Sign

func Sign(msg []byte, privkey []byte, sigType SigType) (*crypto.Signature, error)

Sign takes in signature type, private key and message. Returns a signature for that message. Valid sigTypes are: "secp256k1" and "bls"

func ToPublic added in v1.0.1

func ToPublic(sigType crypto.SigType, pk []byte) ([]byte, error)

ToPublic converts private key to public key

func Verify added in v1.0.1

func Verify(sig *crypto.Signature, addr address.Address, msg []byte) error

Verify verifies signatures

func VerifyAggregate added in v1.0.1

func VerifyAggregate(pubKeys, msgs [][]byte, signature []byte) error

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 SigShim added in v1.0.1

type SigShim interface {
	GenPrivate() ([]byte, error)
	GenPrivateFromSeed(seed io.Reader) ([]byte, error)
	ToPublic(pk []byte) ([]byte, error)
	Sign(pk []byte, msg []byte) ([]byte, error)
	Verify(sig []byte, a address.Address, msg []byte) error
	VerifyAggregate(pubKeys, msgs [][]byte, signature []byte) bool
}

SigShim is used for introducing signature functions

type SigType

type SigType = crypto.SigType

type Signature

type Signature = crypto.Signature

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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