signer

package
v0.0.0-...-deb7540 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Copyright (c) 2019 Polychain Crypto Laboratory, LLC (licensed under the Blue Oak Model License 1.0.0) Modifications Copyright (c) 2021, Foris Limited (licensed under the Apache License, Version 2.0)

Copyright (c) 2019 Polychain Crypto Laboratory, LLC (licensed under the Blue Oak Model License 1.0.0) Modifications Copyright (c) 2021, Foris Limited (licensed under the Apache License, Version 2.0)

Copyright (c) 2019 Polychain Crypto Laboratory, LLC (licensed under the Blue Oak Model License 1.0.0) Modifications Copyright (c) 2021, Foris Limited (licensed under the Apache License, Version 2.0)

Copyright (c) 2019 Polychain Crypto Laboratory, LLC (licensed under the Blue Oak Model License 1.0.0) Modifications Copyright (c) 2021, Foris Limited (licensed under the Apache License, Version 2.0)

Copyright (c) 2019 Polychain Crypto Laboratory, LLC (licensed under the Blue Oak Model License 1.0.0) Modifications Copyright (c) 2021, Foris Limited (licensed under the Apache License, Version 2.0)

Copyright (c) 2019 Polychain Crypto Laboratory, LLC (licensed under the Blue Oak Model License 1.0.0) Modifications Copyright (c) 2021, Foris Limited (licensed under the Apache License, Version 2.0)

Copyright (c) 2019 Polychain Crypto Laboratory, LLC (licensed under the Blue Oak Model License 1.0.0) Modifications Copyright (c) 2021, Foris Limited (licensed under the Apache License, Version 2.0)

Copyright (c) 2019 Polychain Crypto Laboratory, LLC (licensed under the Blue Oak Model License 1.0.0) Modifications Copyright (c) 2021, Foris Limited (licensed under the Apache License, Version 2.0)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalVoteToStep

func CanonicalVoteToStep(vote *tmProto.CanonicalVote) int8

func CheckOnlyDifferByTimestamp

func CheckOnlyDifferByTimestamp(step int8, lastSignBytes []byte, newSignBytes []byte) (time.Time, bool)

func ProposalToStep

func ProposalToStep(_ *tmProto.Proposal) int8

func ReadMsg

func ReadMsg(reader io.Reader) (msg tmProtoPrivval.Message, err error)

ReadMsg reads a message from an io.Reader

func UnpackHRS

func UnpackHRS(signBytes []byte) (height int64, round int64, step int8, chainId string, err error)

UnpackHRS deserializes sign bytes and gets the height, round, and step

func VoteToStep

func VoteToStep(vote *tmProto.Vote) int8

func WriteMsg

func WriteMsg(writer io.Writer, msg tmProtoPrivval.Message) (err error)

WriteMsg writes a message to an io.Writer

Types

type Block

type Block struct {
	Height    int64
	Round     int64
	Step      int8
	SignBytes []byte
	Timestamp time.Time
}

type CoConfig

type CoConfig struct {
	KeySharePath      string `toml:"key_share_file"`
	PrivValStateFile  string `toml:"state_file"`
	ChainID           string `toml:"chain_id"`
	CosignerId        byte   `toml:"cosigner_id"`
	CosignerThreshold byte   `toml:"cosigner_threshold"`
	KeygenProxyPub    string `toml:"keygen_proxy_pub"`
	KeygenProxySub    string `toml:"keygen_proxy_sub"`
	SessionTimeoutSec int    `toml:"session_timeout_sec"`

	ListenAddress string           `toml:"cosigner_listen_address"`
	Nodes         []NodeConfig     `toml:"node"`
	Cosigners     []CosignerConfig `toml:"cosigner"`
}

func LoadConfigFromFile

func LoadConfigFromFile(file string) (CoConfig, error)

type Cosigner

type Cosigner interface {
	// Start signing session
	StartSession(req CosignerStartSessionRequest) (CosignerStartSessionResponse, error)

	// Final round
	EndSession(req CosignerEndSessionRequest) (CosignerEndSessionResponse, error)

	// Set the provided signature
	SetSignature(req CosignerSetSignatureRequest) (CosignerSetSignatureResponse, error)
}

Cosigner interface is a set of methods for an m-of-n threshold signature. This interface abstracts the underlying key storage and management

type CosignerConfig

type CosignerConfig struct {
	ID      int    `toml:"id"`
	Address string `toml:"remote_address"`
}

type CosignerEndSessionRequest

type CosignerEndSessionRequest struct {
	ID        byte
	SignBytes []byte
	PartyIDs  []byte
	Msg1Out   [][]byte
}

func (CosignerEndSessionRequest) PartyId

func (req CosignerEndSessionRequest) PartyId() byte

type CosignerEndSessionResponse

type CosignerEndSessionResponse struct {
	Msg2Out  [][]byte
	MaybeSig []byte
}

type CosignerRequest

type CosignerRequest interface {
	PartyId() byte
}

func MsgToRequest

func MsgToRequest(msg [][]byte) CosignerRequest

type CosignerSetSignatureRequest

type CosignerSetSignatureRequest struct {
	ID        byte
	SignBytes []byte
	Sig       []byte
}

func (CosignerSetSignatureRequest) PartyId

func (req CosignerSetSignatureRequest) PartyId() byte

type CosignerSetSignatureResponse

type CosignerSetSignatureResponse struct {
	ID byte
}

type CosignerStartSessionRequest

type CosignerStartSessionRequest struct {
	ID        byte
	SignBytes []byte
	PartyIDs  []byte
}

func (CosignerStartSessionRequest) PartyId

func (req CosignerStartSessionRequest) PartyId() byte

type CosignerStartSessionResponse

type CosignerStartSessionResponse struct {
	Msg1Out  [][]byte
	MaybeSig []byte
}

type HRSKey

type HRSKey struct {
	Height int64
	Round  int64
	Step   int8
}

func (*HRSKey) Less

func (hrsKey *HRSKey) Less(other HRSKey) bool

return true if we are less than the other key

type HRSMeta

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

type KeyGenOutput

type KeyGenOutput struct {
	Secret *eddsa.SecretShare
	Shares *eddsa.Public
}

func LoadKeygenOutputFromFile

func LoadKeygenOutputFromFile(file string) (KeyGenOutput, error)

type LocalCosigner

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

LocalCosigner responds to sign requests using their share key The cosigner maintains a watermark to avoid double-signing

LocalCosigner signing is thread saafe

func NewLocalCosigner

func NewLocalCosigner(cfg CoConfig) (*LocalCosigner, error)

func (*LocalCosigner) EndSession

func (*LocalCosigner) FinalSign

func (cosigner *LocalCosigner) FinalSign(hrsKey HRSKey, partyIds []byte, msg2out [][]byte) ([]byte, error)

func (*LocalCosigner) SetSignature

func (*LocalCosigner) StartSession

type NodeConfig

type NodeConfig struct {
	Address string `toml:"address"`
}

type PvGuard

type PvGuard struct {
	PrivValidator tm.PrivValidator
	// contains filtered or unexported fields
}

PvGuard guards access to an underlying PrivValidator by using mutexes for each of the PrivValidator interface functions

func (*PvGuard) GetPubKey

func (pv *PvGuard) GetPubKey() (crypto.PubKey, error)

GetPubKey implementes types.PrivValidator

func (*PvGuard) SignProposal

func (pv *PvGuard) SignProposal(chainID string, proposal *tmProto.Proposal) error

SignProposal implementes types.PrivValidator

func (*PvGuard) SignVote

func (pv *PvGuard) SignVote(chainID string, vote *tmProto.Vote) error

SignVote implementes types.PrivValidator

type ReconnRemoteSigner

type ReconnRemoteSigner struct {
	tmService.BaseService
	// contains filtered or unexported fields
}

ReconnRemoteSigner dials using its dialer and responds to any signature requests using its privVal.

func NewReconnRemoteSigner

func NewReconnRemoteSigner(
	address string,
	logger tmLog.Logger,
	chainID string,
	privVal tm.PrivValidator,
	dialer net.Dialer,
) *ReconnRemoteSigner

NewReconnRemoteSigner return a ReconnRemoteSigner that will dial using the given dialer and respond to any signature requests over the connection using the given privVal.

If the connection is broken, the ReconnRemoteSigner will attempt to reconnect.

func (*ReconnRemoteSigner) OnStart

func (rs *ReconnRemoteSigner) OnStart() error

OnStart implements cmn.Service.

type RemoteCosigners

type RemoteCosigners struct {
	Context        *zmq.Context
	Clients        map[*zmq.Socket]byte
	ActiveClients  map[*zmq.Socket]byte
	SessionClients map[*zmq.Socket]byte
	Poller         *zmq.Poller
	LocalID        byte
	Threshold      int
	// contains filtered or unexported fields
}

RemoteCosigners maintains the connections to the remote nodes and collects responses from them

NOT thread safe

func NewRemoteCosigners

func NewRemoteCosigners(cfg CoConfig) (*RemoteCosigners, error)

func (*RemoteCosigners) EndSession

func (*RemoteCosigners) ResetParties

func (cosigners *RemoteCosigners) ResetParties() []byte

func (*RemoteCosigners) SetSignature

func (*RemoteCosigners) StartSession

type SignState

type SignState struct {
	Height    int64            `json:"height"`
	Round     int64            `json:"round"`
	Step      int8             `json:"step"`
	Signature []byte           `json:"signature,omitempty"`
	SignBytes tmBytes.HexBytes `json:"signbytes,omitempty"`
	// contains filtered or unexported fields
}

SignState stores signing information for high level watermark management.

func LoadOrCreateSignState

func LoadOrCreateSignState(filepath string) (SignState, error)

LoadOrCreateSignState loads the sign state from filepath If the sign state could not be loaded, an empty sign state is initialized and saved to filepath.

func LoadSignState

func LoadSignState(filepath string) (SignState, error)

LoadSignState loads a sign state from disk.

func (*SignState) CheckHRS

func (signState *SignState) CheckHRS(height int64, round int64, step int8) (bool, error)

CheckHRS checks the given height, round, step (HRS) against that of the SignState. It returns an error if the arguments constitute a regression, or if they match but the SignBytes are empty. Returns true if the HRS matches the arguments and the SignBytes are not empty (indicating we have already signed for this HRS, and can reuse the existing signature). It panics if the HRS matches the arguments, there's a SignBytes, but no Signature.

func (*SignState) OnlyDifferByTimestamp

func (signState *SignState) OnlyDifferByTimestamp(signBytes []byte) (time.Time, bool)

OnlyDifferByTimestamp returns true if the sign bytes of the sign state are the same as the new sign bytes excluding the timestamp.

func (*SignState) Save

func (signState *SignState) Save()

Save persists the FilePvLastSignState to its filePath.

type SignerServer

type SignerServer struct {
	tmService.BaseService
	Context *zmq.Context
	Server  *zmq.Socket
	Local   *LocalCosigner
}

SignerServer listens on zmq and responds to any signature requests its socket.

func NewSignerServer

func NewSignerServer(logger tmlog.Logger, local *LocalCosigner, config CoConfig) (*SignerServer, error)

NewSignerServer instantiates a local cosigner with the specified key and sign state

func (*SignerServer) OnStart

func (rs *SignerServer) OnStart() error

OnStart implements cmn.Service.

func (*SignerServer) OnStop

func (rs *SignerServer) OnStop()

OnStop implements cmn.Service.

type SortedPartyIds

type SortedPartyIds struct {
	Ids string
}

type ThresholdValidator

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

func NewThresholdValidator

func NewThresholdValidator(cosigner *LocalCosigner, peers *RemoteCosigners) *ThresholdValidator

NewThresholdValidator creates and returns a new ThresholdValidator

func (*ThresholdValidator) GetPubKey

func (pv *ThresholdValidator) GetPubKey() (crypto.PubKey, error)

GetPubKey returns the public key of the validator. Implements PrivValidator.

func (*ThresholdValidator) SignProposal

func (pv *ThresholdValidator) SignProposal(chainID string, proposal *tmProto.Proposal) error

SignProposal signs a canonical representation of the proposal, along with the chainID. Implements PrivValidator.

func (*ThresholdValidator) SignVote

func (pv *ThresholdValidator) SignVote(chainID string, vote *tmProto.Vote) error

SignVote signs a canonical representation of the vote, along with the chainID. Implements PrivValidator.

Jump to

Keyboard shortcuts

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