bls

package
v0.1.1-devnet Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorSecSize returned when the secrete key size is wrong
	ErrorSecSize = errors.New("secret key size is wrong")
	// ErrorSecUnmarshal returned when the secret key is not valid
	ErrorSecUnmarshal = errors.New("secret key bytes are not on curve")
	// ErrorPubKeySize returned when the pubkey size is wrong
	ErrorPubKeySize = errors.New("pub key size is wrong")
	// ErrorPubKeyUnmarshal returned when the pubkey is not valid
	ErrorPubKeyUnmarshal = errors.New("could not unmarshal bytes into public key")
	// ErrorSigSize returned when the signature bytes doesn't match the length
	ErrorSigSize = errors.New("signature should be 96 bytes")
	// ErrorSigUnmarshal returned when the pubkey is not valid
	ErrorSigUnmarshal = errors.New("could not unmarshal bytes into signature")
	// ErrInfinitePubKey returned when the pubkey is zero
	ErrInfinitePubKey = errors.New("public key is zero")
	// ErrZeroSecKey returned when the secret key is zero
	ErrZeroSecKey = errors.New("secret key is zero")
)
View Source
var Prefix = params.MainNet.AccountPrefixes

Functions

func Initialize

func Initialize(c *params.ChainParams)

func VerifyMultipleSignatures

func VerifyMultipleSignatures(sigs []*Signature, msgs [][32]byte, pubKeys []*PublicKey) (bool, error)

VerifyMultipleSignatures verifies a non-singular set of signatures and its respective pubkeys and messages. This method provides a safe way to verify multiple signatures at once. We pick a number randomly from 1 to max uint64 and then multiply the signature by it. We continue doing this for all signatures and its respective pubkeys. S* = S_1 * r_1 + S_2 * r_2 + ... + S_n * r_n P'_{i,j} = P_{i,j} * r_i e(S*, G) = \prod_{i=1}^n \prod_{j=1}^{m_i} e(P'_{i,j}, M_{i,j}) Using this we can verify multiple signatures safely.

Types

type KeyPair

type KeyPair struct {
	Public  string `json:"public"`
	Private string `json:"private"`
}

KeyPair is an interface struct to serve keypairs

type PublicKey

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

PublicKey used in the BLS signature scheme.

func AggregatePublicKeys

func AggregatePublicKeys(pubs [][]byte) (*PublicKey, error)

AggregatePublicKeys aggregates the provided raw public keys into a single key.

func PublicKeyFromBytes

func PublicKeyFromBytes(pubKey []byte) (*PublicKey, error)

PublicKeyFromBytes creates a BLS public key from a BigEndian byte slice.

func (*PublicKey) Aggregate

func (p *PublicKey) Aggregate(p2 *PublicKey) *PublicKey

Aggregate two public keys.

func (*PublicKey) Copy

func (p *PublicKey) Copy() *PublicKey

Copy the public key to a new pointer reference.

func (*PublicKey) Hash

func (p *PublicKey) Hash() ([20]byte, error)

Hash calculates the hash of the public key.

func (*PublicKey) IsInfinite

func (p *PublicKey) IsInfinite() bool

IsInfinite checks if the public key is infinite.

func (*PublicKey) Marshal

func (p *PublicKey) Marshal() []byte

Marshal a public key into a LittleEndian byte slice.

func (*PublicKey) ToAccount

func (p *PublicKey) ToAccount() string

ToAccount converts the public key to a Bech32 address.

type Rand

type Rand = mrand.Rand

Rand is alias for underlying random generator.

func NewGenerator

func NewGenerator() *Rand

NewGenerator returns a new generator that uses random values from crypto/rand as a source (cryptographically secure random number generator). Panics if crypto/rand input cannot be read. Use it for everything where crypto secure non-deterministic randomness is required. Performance takes a hit, so use sparingly.

type SecretKey

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

SecretKey used in the BLS signature scheme.

func RandKey

func RandKey() (*SecretKey, error)

RandKey creates a new private key using a random method provided as an io.Reader.

func SecretKeyFromBytes

func SecretKeyFromBytes(privKey []byte) (*SecretKey, error)

SecretKeyFromBytes creates a BLS private key from a BigEndian byte slice.

func (*SecretKey) Marshal

func (s *SecretKey) Marshal() []byte

Marshal a secret key into a LittleEndian byte slice.

func (*SecretKey) PublicKey

func (s *SecretKey) PublicKey() *PublicKey

PublicKey obtains the public key corresponding to the BLS secret key.

func (*SecretKey) Sign

func (s *SecretKey) Sign(msg []byte) *Signature

Sign a message using a secret key - in a beacon/validator client.

In IETF draft BLS specification: Sign(SK, message) -> signature: a signing algorithm that generates

a deterministic signature given a secret key SK and a message.

In ETH2.0 specification: def Sign(SK: int, message: Bytes) -> BLSSignature

func (*SecretKey) ToWIF

func (s *SecretKey) ToWIF() string

ToWIF converts the private key to a Bech32 encoded string.

type Signature

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

Signature used in the BLS signature scheme.

func Aggregate deprecated

func Aggregate(sigs []*Signature) *Signature

Aggregate is an alias for AggregateSignatures, defined to conform to BLS specification.

In IETF draft BLS specification: Aggregate(signature_1, ..., signature_n) -> signature: an

aggregation algorithm that compresses a collection of signatures
into a single signature.

In ETH2.0 specification: def Aggregate(signatures: Sequence[BLSSignature]) -> BLSSignature

Deprecated: Use AggregateSignatures.

func AggregateSignatures

func AggregateSignatures(sigs []*Signature) *Signature

AggregateSignatures converts a list of signatures into a single, aggregated sig.

func NewAggregateSignature

func NewAggregateSignature() *Signature

NewAggregateSignature creates a blank aggregate signature.

func SignatureFromBytes

func SignatureFromBytes(sig []byte) (*Signature, error)

SignatureFromBytes creates a BLS signature from a LittleEndian byte slice.

func (*Signature) AggregateVerify

func (s *Signature) AggregateVerify(pubKeys []*PublicKey, msgs [][32]byte) bool

AggregateVerify verifies each public key against its respective message. This is vulnerable to rogue public-key attack. Each user must provide a proof-of-knowledge of the public key.

In IETF draft BLS specification: AggregateVerify((PK_1, message_1), ..., (PK_n, message_n),

signature) -> VALID or INVALID: an aggregate verification
algorithm that outputs VALID if signature is a valid aggregated
signature for a collection of public keys and messages, and
outputs INVALID otherwise.

In ETH2.0 specification: def AggregateVerify(pairs: Sequence[PK: BLSPubkey, message: Bytes], signature: BLSSignature) -> boo

func (*Signature) Copy

func (s *Signature) Copy() *Signature

Copy returns a full deep copy of a signature.

func (*Signature) FastAggregateVerify

func (s *Signature) FastAggregateVerify(pubKeys []*PublicKey, msg [32]byte) bool

FastAggregateVerify verifies all the provided public keys with their aggregated signature.

In IETF draft BLS specification: FastAggregateVerify(PK_1, ..., PK_n, message, signature) -> VALID

or INVALID: a verification algorithm for the aggregate of multiple
signatures on the same message.  This function is faster than
AggregateVerify.

In ETH2.0 specification: def FastAggregateVerify(PKs: Sequence[BLSPubkey], message: Bytes, signature: BLSSignature) -> bool

func (*Signature) Marshal

func (s *Signature) Marshal() []byte

Marshal a signature into a LittleEndian byte slice.

func (*Signature) Verify

func (s *Signature) Verify(pubKey *PublicKey, msg []byte) bool

Verify a bls signature given a public key, a message.

In IETF draft BLS specification: Verify(PK, message, signature) -> VALID or INVALID: a verification

algorithm that outputs VALID if signature is a valid signature of
message under public key PK, and INVALID otherwise.

In ETH2.0 specification: def Verify(PK: BLSPubkey, message: Bytes, signature: BLSSignature) -> bool

Directories

Path Synopsis
Code generated by fastssz.
Code generated by fastssz.

Jump to

Keyboard shortcuts

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