signer

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 14 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// IstanbulDigest represents a hash of "Istanbul practical byzantine fault tolerance"
	// to identify whether the block is from Istanbul consensus engine
	IstanbulDigest = types.StringToHash("0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365")

	// IstanbulExtraVanity represents a fixed number of extra-data bytes reserved for proposer vanity
	IstanbulExtraVanity = 32

	// IstanbulExtraSeal represents the fixed number of extra-data bytes reserved for proposer seal
	IstanbulExtraSeal = 65
)
View Source
var (
	ErrEmptyCommittedSeals        = errors.New("empty committed seals")
	ErrEmptyParentCommittedSeals  = errors.New("empty parent committed seals")
	ErrInvalidCommittedSealLength = errors.New("invalid committed seal length")
	ErrInvalidCommittedSealType   = errors.New("invalid committed seal type")
	ErrRepeatedCommittedSeal      = errors.New("repeated seal in committed seals")
	ErrNonValidatorCommittedSeal  = errors.New("found committed seal signed by non validator")
	ErrNotEnoughCommittedSeals    = errors.New("not enough seals to seal block")
	ErrSignerMismatch             = errors.New("mismatch address between signer and message sender")
	ErrValidatorNotFound          = errors.New("validator not found in validator set")
	ErrInvalidValidators          = errors.New("invalid validators type")
	ErrInvalidValidator           = errors.New("invalid validator type")
	ErrInvalidSignature           = errors.New("invalid signature")
)

Functions

func UseIstanbulHeaderHashInTest

func UseIstanbulHeaderHashInTest(t *testing.T, signer Signer)

UseIstanbulHeaderHashInTest is a helper function for the test

Types

type AggregatedSeal

type AggregatedSeal struct {
	Bitmap    *big.Int
	Signature []byte
}

func (*AggregatedSeal) MarshalRLPWith

func (s *AggregatedSeal) MarshalRLPWith(ar *fastrlp.Arena) *fastrlp.Value

func (*AggregatedSeal) Num

func (s *AggregatedSeal) Num() int

func (*AggregatedSeal) UnmarshalRLPFrom

func (s *AggregatedSeal) UnmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error

type BLSKeyManager

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

BLSKeyManager is a module that holds ECDSA and BLS keys and implements methods of signing by these keys

func (*BLSKeyManager) Address

func (s *BLSKeyManager) Address() types.Address

Address returns the address of KeyManager

func (*BLSKeyManager) Ecrecover

func (s *BLSKeyManager) Ecrecover(sig, digest []byte) (types.Address, error)

func (*BLSKeyManager) GenerateCommittedSeals

func (s *BLSKeyManager) GenerateCommittedSeals(
	sealMap map[types.Address][]byte,
	set validators.Validators,
) (Seals, error)

func (*BLSKeyManager) NewEmptyCommittedSeals

func (s *BLSKeyManager) NewEmptyCommittedSeals() Seals

NewEmptyCommittedSeals returns empty CommittedSeals BLSKeyManager uses

func (*BLSKeyManager) NewEmptyValidators

func (s *BLSKeyManager) NewEmptyValidators() validators.Validators

NewEmptyValidators returns empty validator collection BLSKeyManager uses

func (*BLSKeyManager) SignCommittedSeal

func (s *BLSKeyManager) SignCommittedSeal(data []byte) ([]byte, error)

func (*BLSKeyManager) SignIBFTMessage

func (s *BLSKeyManager) SignIBFTMessage(msg []byte) ([]byte, error)

func (*BLSKeyManager) SignProposerSeal

func (s *BLSKeyManager) SignProposerSeal(data []byte) ([]byte, error)

func (*BLSKeyManager) Type

Type returns the validator type KeyManager supports

func (*BLSKeyManager) VerifyCommittedSeal

func (s *BLSKeyManager) VerifyCommittedSeal(
	set validators.Validators,
	addr types.Address,
	rawSignature []byte,
	hash []byte,
) error

func (*BLSKeyManager) VerifyCommittedSeals

func (s *BLSKeyManager) VerifyCommittedSeals(
	rawCommittedSeal Seals,
	message []byte,
	vals validators.Validators,
) (int, error)

type ECDSAKeyManager

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

ECDSAKeyManager is a module that holds ECDSA key and implements methods of signing by this key

func (*ECDSAKeyManager) Address

func (s *ECDSAKeyManager) Address() types.Address

Address returns the address of KeyManager

func (*ECDSAKeyManager) Ecrecover

func (s *ECDSAKeyManager) Ecrecover(sig, digest []byte) (types.Address, error)

func (*ECDSAKeyManager) GenerateCommittedSeals

func (s *ECDSAKeyManager) GenerateCommittedSeals(
	sealMap map[types.Address][]byte,
	_ validators.Validators,
) (Seals, error)

func (*ECDSAKeyManager) NewEmptyCommittedSeals

func (s *ECDSAKeyManager) NewEmptyCommittedSeals() Seals

NewEmptyCommittedSeals returns empty CommittedSeals ECDSAKeyManager uses

func (*ECDSAKeyManager) NewEmptyValidators

func (s *ECDSAKeyManager) NewEmptyValidators() validators.Validators

NewEmptyValidators returns empty validator collection ECDSAKeyManager uses

func (*ECDSAKeyManager) SignCommittedSeal

func (s *ECDSAKeyManager) SignCommittedSeal(message []byte) ([]byte, error)

SignProposerSeal signs the given message by ECDSA key the ECDSAKeyManager holds for committed seal

func (*ECDSAKeyManager) SignIBFTMessage

func (s *ECDSAKeyManager) SignIBFTMessage(msg []byte) ([]byte, error)

func (*ECDSAKeyManager) SignProposerSeal

func (s *ECDSAKeyManager) SignProposerSeal(message []byte) ([]byte, error)

SignProposerSeal signs the given message by ECDSA key the ECDSAKeyManager holds for ProposerSeal

func (*ECDSAKeyManager) Type

Type returns the validator type KeyManager supports

func (*ECDSAKeyManager) VerifyCommittedSeal

func (s *ECDSAKeyManager) VerifyCommittedSeal(
	vals validators.Validators,
	address types.Address,
	signature []byte,
	message []byte,
) error

VerifyCommittedSeal verifies a committed seal

func (*ECDSAKeyManager) VerifyCommittedSeals

func (s *ECDSAKeyManager) VerifyCommittedSeals(
	rawCommittedSeal Seals,
	digest []byte,
	vals validators.Validators,
) (int, error)

type IstanbulExtra

type IstanbulExtra struct {
	Validators           validators.Validators
	ProposerSeal         []byte
	CommittedSeals       Seals
	ParentCommittedSeals Seals
	RoundNumber          *uint64
}

IstanbulExtra defines the structure of the extra field for Istanbul

func (*IstanbulExtra) MarshalRLPTo

func (i *IstanbulExtra) MarshalRLPTo(dst []byte) []byte

MarshalRLPTo defines the marshal function wrapper for IstanbulExtra

func (*IstanbulExtra) MarshalRLPWith

func (i *IstanbulExtra) MarshalRLPWith(ar *fastrlp.Arena) *fastrlp.Value

MarshalRLPWith defines the marshal function implementation for IstanbulExtra

func (*IstanbulExtra) UnmarshalRLP

func (i *IstanbulExtra) UnmarshalRLP(input []byte) error

UnmarshalRLP defines the unmarshal function wrapper for IstanbulExtra

func (*IstanbulExtra) UnmarshalRLPFrom

func (i *IstanbulExtra) UnmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error

UnmarshalRLPFrom defines the unmarshal implementation for IstanbulExtra

type KeyManager

type KeyManager interface {
	// Type returns Validator type signer supports
	Type() validators.ValidatorType
	// Address returns an address of signer
	Address() types.Address
	// NewEmptyValidators creates empty validator collection the Signer expects
	NewEmptyValidators() validators.Validators
	// NewEmptyCommittedSeals creates empty committed seals the Signer expects
	NewEmptyCommittedSeals() Seals
	// SignProposerSeal creates a signature for ProposerSeal
	SignProposerSeal(hash []byte) ([]byte, error)
	// SignCommittedSeal creates a signature for committed seal
	SignCommittedSeal(hash []byte) ([]byte, error)
	// VerifyCommittedSeal verifies a committed seal
	VerifyCommittedSeal(vals validators.Validators, signer types.Address, sig, hash []byte) error
	// GenerateCommittedSeals creates CommittedSeals from committed seals
	GenerateCommittedSeals(sealsByValidator map[types.Address][]byte, vals validators.Validators) (Seals, error)
	// VerifyCommittedSeals verifies CommittedSeals
	VerifyCommittedSeals(seals Seals, hash []byte, vals validators.Validators) (int, error)
	// SignIBFTMessage signs for arbitrary bytes message
	SignIBFTMessage(msg []byte) ([]byte, error)
	// Ecrecover recovers address from signature and message
	Ecrecover(sig []byte, msg []byte) (types.Address, error)
}

KeyManager is a delegated module that signs data

func NewBLSKeyManager

func NewBLSKeyManager(manager secrets.SecretsManager) (KeyManager, error)

NewBLSKeyManager initializes BLSKeyManager by the ECDSA key and BLS key which are loaded from SecretsManager

func NewBLSKeyManagerFromKeys

func NewBLSKeyManagerFromKeys(ecdsaKey *ecdsa.PrivateKey, blsKey *bls_sig.SecretKey) KeyManager

NewBLSKeyManagerFromKeys initializes BLSKeyManager from the given ECDSA and BLS keys

func NewECDSAKeyManager

func NewECDSAKeyManager(manager secrets.SecretsManager) (KeyManager, error)

NewECDSAKeyManager initializes ECDSAKeyManager by the ECDSA key loaded from SecretsManager

func NewECDSAKeyManagerFromKey

func NewECDSAKeyManagerFromKey(key *ecdsa.PrivateKey) KeyManager

NewECDSAKeyManagerFromKey initializes ECDSAKeyManager from the given ECDSA key

func NewKeyManagerFromType

func NewKeyManagerFromType(
	secretManager secrets.SecretsManager,
	validatorType validators.ValidatorType,
) (KeyManager, error)

NewKeyManagerFromType creates KeyManager based on the given type

type Seals

type Seals interface {
	// Number of committed seals
	Num() int
	MarshalRLPWith(ar *fastrlp.Arena) *fastrlp.Value
	UnmarshalRLPFrom(*fastrlp.Parser, *fastrlp.Value) error
}

type SerializedSeal

type SerializedSeal [][]byte

func (*SerializedSeal) MarshalRLPWith

func (s *SerializedSeal) MarshalRLPWith(ar *fastrlp.Arena) *fastrlp.Value

func (*SerializedSeal) Num

func (s *SerializedSeal) Num() int

func (*SerializedSeal) UnmarshalRLPFrom

func (s *SerializedSeal) UnmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error

type Signer

type Signer interface {
	Type() validators.ValidatorType
	Address() types.Address

	// IBFT Extra
	InitIBFTExtra(*types.Header, validators.Validators, Seals)
	GetIBFTExtra(*types.Header) (*IstanbulExtra, error)
	GetValidators(*types.Header) (validators.Validators, error)

	// ProposerSeal
	WriteProposerSeal(*types.Header) (*types.Header, error)
	EcrecoverFromHeader(*types.Header) (types.Address, error)

	// CommittedSeal
	CreateCommittedSeal([]byte) ([]byte, error)
	VerifyCommittedSeal(validators.Validators, types.Address, []byte, []byte) error

	// CommittedSeals
	WriteCommittedSeals(
		header *types.Header,
		roundNumber uint64,
		sealMap map[types.Address][]byte,
	) (*types.Header, error)
	VerifyCommittedSeals(
		hash types.Hash,
		committedSeals Seals,
		validators validators.Validators,
		quorumSize int,
	) error

	// ParentCommittedSeals
	VerifyParentCommittedSeals(
		parentHash types.Hash,
		header *types.Header,
		parentValidators validators.Validators,
		quorum int,
		mustExist bool,
	) error

	// IBFTMessage
	SignIBFTMessage([]byte) ([]byte, error)
	EcrecoverFromIBFTMessage([]byte, []byte) (types.Address, error)

	// Hash of Header
	CalculateHeaderHash(*types.Header) (types.Hash, error)
	FilterHeaderForHash(*types.Header) (*types.Header, error)
}

Signer is responsible for signing for blocks and messages in IBFT

type SignerImpl

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

SignerImpl is an implementation that meets Signer

func NewSigner

func NewSigner(
	keyManager KeyManager,
	parentKeyManager KeyManager,
) *SignerImpl

NewSigner is a constructor of SignerImpl

func (*SignerImpl) Address

func (s *SignerImpl) Address() types.Address

Address returns the signer's address

func (*SignerImpl) CalculateHeaderHash

func (s *SignerImpl) CalculateHeaderHash(header *types.Header) (types.Hash, error)

CalculateHeaderHash calculates header hash for IBFT Extra

func (*SignerImpl) CreateCommittedSeal

func (s *SignerImpl) CreateCommittedSeal(hash []byte) ([]byte, error)

CreateCommittedSeal returns CommittedSeal from given hash

func (*SignerImpl) EcrecoverFromHeader

func (s *SignerImpl) EcrecoverFromHeader(header *types.Header) (types.Address, error)

EcrecoverFromIBFTMessage recovers signer address from given signature and header hash

func (*SignerImpl) EcrecoverFromIBFTMessage

func (s *SignerImpl) EcrecoverFromIBFTMessage(signature, digest []byte) (types.Address, error)

EcrecoverFromIBFTMessage recovers signer address from given signature and digest

func (*SignerImpl) FilterHeaderForHash added in v0.8.0

func (s *SignerImpl) FilterHeaderForHash(header *types.Header) (*types.Header, error)

filterHeaderForHash removes unnecessary fields from IBFT Extra of the header for hash calculation

func (*SignerImpl) GetIBFTExtra

func (s *SignerImpl) GetIBFTExtra(header *types.Header) (*IstanbulExtra, error)

GetIBFTExtra extracts IBFT Extra from the given header

func (*SignerImpl) GetParentCommittedSeals

func (s *SignerImpl) GetParentCommittedSeals(header *types.Header) (Seals, error)

GetParentCommittedSeals extracts Parent Committed Seals from IBFT Extra in Header

func (*SignerImpl) GetValidators

func (s *SignerImpl) GetValidators(header *types.Header) (validators.Validators, error)

func (*SignerImpl) InitIBFTExtra

func (s *SignerImpl) InitIBFTExtra(
	header *types.Header,
	validators validators.Validators,
	parentCommittedSeals Seals,
)

InitIBFTExtra initializes the extra field in the given header based on given validators and parent committed seals

func (*SignerImpl) SignIBFTMessage

func (s *SignerImpl) SignIBFTMessage(msg []byte) ([]byte, error)

SignIBFTMessage signs arbitrary message

func (*SignerImpl) Type

Type returns that validator type the signer expects

func (*SignerImpl) VerifyCommittedSeal

func (s *SignerImpl) VerifyCommittedSeal(
	validators validators.Validators,
	signer types.Address,
	signature, hash []byte,
) error

CreateCommittedSeal verifies a CommittedSeal

func (*SignerImpl) VerifyCommittedSeals

func (s *SignerImpl) VerifyCommittedSeals(
	hash types.Hash,
	committedSeals Seals,
	validators validators.Validators,
	quorumSize int,
) error

VerifyCommittedSeals verifies CommittedSeals in IBFT Extra of the header

func (*SignerImpl) VerifyParentCommittedSeals

func (s *SignerImpl) VerifyParentCommittedSeals(
	parentHash types.Hash,
	header *types.Header,
	parentValidators validators.Validators,
	quorum int,
	mustExist bool,
) error

VerifyParentCommittedSeals verifies ParentCommittedSeals in IBFT Extra of the header

func (*SignerImpl) WriteCommittedSeals

func (s *SignerImpl) WriteCommittedSeals(
	header *types.Header,
	roundNumber uint64,
	sealMap map[types.Address][]byte,
) (*types.Header, error)

WriteCommittedSeals builds and writes CommittedSeals into IBFT Extra of the header

func (*SignerImpl) WriteProposerSeal

func (s *SignerImpl) WriteProposerSeal(header *types.Header) (*types.Header, error)

WriteProposerSeal signs and set ProposerSeal into IBFT Extra of the header

Jump to

Keyboard shortcuts

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