bls

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2020 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package bls implements a go-wrapper around a library implementing the the BLS12-381 curve and signature scheme. This package exposes a public API for verifying and aggregating BLS signatures used by Ethereum 2.0.

Index

Constants

View Source
const CurveOrder = "52435875175126190479447740508185965837690552500527637822603658699938581184513"

CurveOrder for the BLS12-381 curve.

View Source
const DomainByteLength = 4

DomainByteLength length of domain byte array.

View Source
const ForkVersionByteLength = 4

ForkVersionByteLength length of fork version byte array.

Variables

This section is empty.

Functions

func ComputeDomain added in v0.2.3

func ComputeDomain(domainType [DomainByteLength]byte) uint64

ComputeDomain returns the domain version for BLS private key to sign and verify with a zeroed 4-byte array as the fork version.

def compute_domain(domain_type: DomainType, fork_version: Version=Version()) -> Domain:

"""
Return the domain for the ``domain_type`` and ``fork_version``.
"""
return Domain(domain_type + fork_version)

func Domain

func Domain(domainType [DomainByteLength]byte, forkVersion [ForkVersionByteLength]byte) uint64

Domain returns the bls domain given by the domain type and the operation 4 byte fork version.

Spec pseudocode definition:

def get_domain(state: BeaconState, domain_type: DomainType, message_epoch: Epoch=None) -> Domain:
  """
  Return the signature domain (fork version concatenated with domain type) of a message.
  """
  epoch = get_current_epoch(state) if message_epoch is None else message_epoch
  fork_version = state.fork.previous_version if epoch < state.fork.epoch else state.fork.current_version
  return compute_domain(domain_type, fork_version)

func HashWithDomain

func HashWithDomain(messageHash [32]byte, domain [8]byte) []byte

HashWithDomain hashes 32 byte message and uint64 domain parameters a Fp2 element

Types

type PublicKey

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

PublicKey used in the BLS signature scheme.

func NewAggregatePubkey

func NewAggregatePubkey() *PublicKey

NewAggregatePubkey creates a blank public key.

func PublicKeyFromBytes

func PublicKeyFromBytes(pub []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, error)

Copy the public key to a new pointer reference.

func (*PublicKey) Marshal

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

Marshal a public key into a LittleEndian byte slice.

type SecretKey

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

SecretKey used in the BLS signature scheme.

func RandKey

func RandKey() *SecretKey

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

func SecretKeyFromBytes

func SecretKeyFromBytes(priv []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, domain uint64) *Signature

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

type Signature

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

Signature used in the BLS signature scheme.

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) Marshal

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

Marshal a signature into a LittleEndian byte slice.

func (*Signature) Verify

func (s *Signature) Verify(msg []byte, pub *PublicKey, domain uint64) bool

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

func (*Signature) VerifyAggregate

func (s *Signature) VerifyAggregate(pubKeys []*PublicKey, msg [][32]byte, domain uint64) bool

VerifyAggregate 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.

func (*Signature) VerifyAggregateCommon

func (s *Signature) VerifyAggregateCommon(pubKeys []*PublicKey, msg [32]byte, domain uint64) bool

VerifyAggregateCommon 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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