types

package module
v2.8.2 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: Apache-2.0 Imports: 5 Imported by: 110

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

Package types provides generic types for the Ethereum consensus system.

Code generated by fastssz. DO NOT EDIT. Hash: 8081802cb4896b4b267c7066039a5f7fd3ba8d657e72369339f506ac22bc50b4

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 = DomainType{5, 0, 0, 0}
	// DomainAggregateAndProof is a domain constant.
	DomainAggregateAndProof = DomainType{6, 0, 0, 0}
	// DomainSyncCommittee is a domain constant.
	DomainSyncCommittee = DomainType{7, 0, 0, 0}
	// DomainSyncCommitteeSelectionProof is a domain constant.
	DomainSyncCommitteeSelectionProof = DomainType{8, 0, 0, 0}
	// DomainContributionAndProof is a domain constant.
	DomainContributionAndProof = DomainType{9, 0, 0, 0}
	// DomainBlsToExecutionChange is a domain constant.
	DomainBlsToExecutionChange = DomainType{0x0A, 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 added in v2.5.1

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 added in v2.2.0

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 added in v2.1.0

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 added in v2.5.1

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

ForkData is a spec struct.

func (*ForkData) GetTree added in v2.7.0

func (f *ForkData) GetTree() (*ssz.Node, error)

GetTree ssz hashes the ForkData object

func (*ForkData) HashTreeRoot added in v2.5.1

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

HashTreeRoot ssz hashes the ForkData object

func (*ForkData) HashTreeRootWith added in v2.5.1

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

HashTreeRootWith ssz hashes the ForkData object with a hasher

func (*ForkData) MarshalSSZ added in v2.5.1

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

MarshalSSZ ssz marshals the ForkData object

func (*ForkData) MarshalSSZTo added in v2.5.1

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

MarshalSSZTo ssz marshals the ForkData object to a target array

func (*ForkData) SizeSSZ added in v2.5.1

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

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

func (*ForkData) UnmarshalSSZ added in v2.5.1

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
}

Signature is an interface for signatures.

func BLSSignatureFromBytes

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

BLSSignatureFromBytes creates a BLS signature from a byte slice.

func BLSSignatureFromSig added in v2.4.3

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