types

package module
v2.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2020 License: Apache-2.0 Imports: 3 Imported by: 1

README

go-eth2-types

Tag License GoDoc Travis CI codecov.io

Go library providing Ethereum 2 types.

Please note that this library uses standards that are not yet final, and as such may result in changes that alter public and private keys. Do not use this library for production use just yet

Table of Contents

Install

go-eth2-types is a standard Go module which can be installed with:

go get github.com/wealdtech/go-eth2-types

Usage

Before using any cryptographic features you must call InitBLS().

Please read the Go documentation for this library for interface information.

Maintainers

Jim McDonald: @mcdee.

Contribute

Contributions welcome. Please check out the issues.

License

Apache-2.0 © 2019 Weald Technology Trading Ltd

Documentation

Overview

Code generated by fastssz. DO NOT EDIT.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DomainBeaconProposer is a domain constant.
	DomainBeaconProposer = DomainType{0, 0, 0, 0}
	// DomainBeaconAttester is a domain constant.
	DomainBeaconAttester = DomainType{1, 0, 0, 0}
	// DomainRANDAO is a domain constant.
	DomainRANDAO = DomainType{2, 0, 0, 0}
	// DomainDeposit is a domain constant.
	DomainDeposit = DomainType{3, 0, 0, 0}
	// DomainVoluntaryExit is a domain constant.
	DomainVoluntaryExit = DomainType{4, 0, 0, 0}
	// DomainSelectionProof is a domain constant.
	DomainSelectionProof = []byte{5, 0, 0, 0}
	// DomainAggregateAndProof is a domain constant.
	DomainAggregateAndProof = []byte{6, 0, 0, 0}
)
View Source
var ErrMalformed = errors.New("malformed representation")

ErrMalformed is returned when an external representation cannot be turned in to a native representation

View Source
var ZeroForkVersion = []byte{0, 0, 0, 0}

ZeroForkVersion is an empty fork version.

View Source
var ZeroGenesisValidatorsRoot = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

ZeroGenesisValidatorsRoot is an empty genesis validators root.

Functions

func ComputeDomain

func ComputeDomain(domainType DomainType, forkVersion []byte, genesisValidatorsRoot []byte) ([]byte, error)

ComputeDomain computes a domain.

func Domain

func Domain(domainType DomainType, forkVersion []byte, genesisValidatorsRoot []byte) []byte

Domain returns a complete domain. Deprecated: due to panicking on error. Use ComputeDomain() instead.

func InitBLS

func InitBLS() error

InitBLS initialises the BLS library with the appropriate curve and parameters for Ethereum 2.

Types

type BLSPrivateKey

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

BLSPrivateKey is a private key in Ethereum 2. It is a point on the BLS12-381 curve.

func BLSPrivateKeyFromBytes

func BLSPrivateKeyFromBytes(priv []byte) (*BLSPrivateKey, error)

BLSPrivateKeyFromBytes creates a BLS private key from a byte slice.

func GenerateBLSPrivateKey

func GenerateBLSPrivateKey() (*BLSPrivateKey, error)

GenerateBLSPrivateKey generates a random BLS private key.

func (*BLSPrivateKey) Marshal

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

Marshal a secret key into a byte slice.

func (*BLSPrivateKey) PublicKey

func (p *BLSPrivateKey) PublicKey() PublicKey

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

func (*BLSPrivateKey) Sign

func (p *BLSPrivateKey) Sign(msg []byte) Signature

Sign a message using a secret key.

type BLSPublicKey

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

BLSPublicKey used in the BLS signature scheme.

func BLSPublicKeyFromBytes

func BLSPublicKeyFromBytes(pub []byte) (*BLSPublicKey, error)

BLSPublicKeyFromBytes creates a BLS public key from a byte slice.

func (*BLSPublicKey) Aggregate

func (k *BLSPublicKey) Aggregate(other PublicKey)

Aggregate two public keys. This updates the value of the existing key.

func (*BLSPublicKey) Copy

func (k *BLSPublicKey) Copy() PublicKey

Copy creates a copy of the public key.

func (*BLSPublicKey) Marshal

func (k *BLSPublicKey) Marshal() []byte

Marshal a BLS public key into a byte slice.

type BLSSignature

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

BLSSignature is a BLS signature.

func AggregateSignatures

func AggregateSignatures(sigs []Signature) *BLSSignature

AggregateSignatures aggregates signatures.

func (*BLSSignature) Marshal

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

Marshal a signature into a byte slice.

func (*BLSSignature) Verify

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

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

func (*BLSSignature) VerifyAggregate

func (s *BLSSignature) VerifyAggregate(msgs [][]byte, pubKeys []PublicKey) bool

VerifyAggregate verifies each public key against its respective message. Note: this is vulnerable to a rogue public-key attack.

func (*BLSSignature) VerifyAggregateCommon

func (s *BLSSignature) VerifyAggregateCommon(msg []byte, pubKeys []PublicKey) bool

VerifyAggregateCommon verifies each public key against a single message. Note: this is vulnerable to a rogue public-key attack.

type DomainType

type DomainType [4]byte

DomainType defines the type of the domain, as per https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md#custom-types

type ForkData

type ForkData struct {
	CurrentVersion        []byte `ssz-size:"4"`
	GenesisValidatorsRoot []byte `ssz-size:"32"`
}

ForkData is a spec struct.

func (*ForkData) HashTreeRoot

func (f *ForkData) HashTreeRoot() ([32]byte, error)

HashTreeRoot ssz hashes the ForkData object

func (*ForkData) HashTreeRootWith

func (f *ForkData) HashTreeRootWith(hh *ssz.Hasher) (err error)

HashTreeRootWith ssz hashes the ForkData object with a hasher

func (*ForkData) MarshalSSZ

func (f *ForkData) MarshalSSZ() ([]byte, error)

MarshalSSZ ssz marshals the ForkData object

func (*ForkData) MarshalSSZTo

func (f *ForkData) MarshalSSZTo(buf []byte) (dst []byte, err error)

MarshalSSZTo ssz marshals the ForkData object to a target array

func (*ForkData) SizeSSZ

func (f *ForkData) SizeSSZ() (size int)

SizeSSZ returns the ssz encoded size in bytes for the ForkData object

func (*ForkData) UnmarshalSSZ

func (f *ForkData) UnmarshalSSZ(buf []byte) error

UnmarshalSSZ ssz unmarshals the ForkData object

type PrivateKey

type PrivateKey interface {
	PublicKey() PublicKey
	Sign(msg []byte) Signature
	Marshal() []byte
}

PrivateKey is a private key in Ethereum 2.

type PublicKey

type PublicKey interface {
	Marshal() []byte
	Aggregate(other PublicKey)
	Copy() PublicKey
}

PublicKey is an interface for public keys

type Signature

type Signature interface {
	Verify(msg []byte, pub PublicKey) bool
	VerifyAggregate(msgs [][]byte, pubKeys []PublicKey) bool
	VerifyAggregateCommon(msg []byte, pubKeys []PublicKey) bool
	Marshal() []byte
}

func BLSSignatureFromBytes

func BLSSignatureFromBytes(data []byte) (Signature, error)

BLSSignatureFromBytes creates a BLS signature from a byte slice.

func BLSSignatureFromSig

func BLSSignatureFromSig(sig bls.Sign) (Signature, error)

BLSSignatureFromSig creates a BLS signature from an existing signature.

Jump to

Keyboard shortcuts

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