key

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: Apache-2.0, MIT Imports: 25 Imported by: 8

Documentation

Index

Constants

View Source
const GroupFolderName = "groups"

GroupFolderName is the name of the folder where drand keeps its group files

View Source
const KeyFolderName = "key"

KeyFolderName is the name of the folder where drand keeps its keys

Variables

AuthScheme is the signature scheme used to identify public identities

View Source
var DKGAuthScheme = schnorr.NewScheme(&schnorrSuite{KeyGroup})

DKGAuthScheme is the signature scheme used to authentify packets during a broadcast during a DKG

View Source
var KeyGroup = Pairing.G1()

KeyGroup is the group used to create the keys

View Source
var Pairing = bls.NewBLS12381Suite()

Pairing is the main pairing suite used by drand. New interesting curves should be allowed by drand, such as BLS12-381.

Scheme is the signature scheme used, defining over which curve the signature and keys respectively are.

View Source
var SigGroup = Pairing.G2()

SigGroup is the group used to create the signatures; it must always be different than KeyGroup: G1 key group and G2 sig group or G1 sig group and G2 keygroup.

Functions

func DefaultThreshold

func DefaultThreshold(n int) int

DefaultThreshold return floor(n / 2) + 1

func Delete added in v0.5.2

func Delete(filePath string) error

Delete the resource denoted by the given path. If it is a file, it deletes the file; if it is a folder it delete the folder and all its content.

func Load

func Load(filePath string, t Tomler) error

Load the given Tomler from the given file path.

func MinimumT added in v0.7.1

func MinimumT(n int) int

MinimumT calculates the threshold needed for the group to produce sufficient shares to decode

func PointToString added in v0.4.0

func PointToString(p kyber.Point) string

PointToString returns a hex-encoded string representation of the given point.

func Save

func Save(filePath string, t Tomler, secure bool) error

Save the given Tomler interface to the given path. If secure is true, the file will have a 0700 security. TODO: move that to fs/

func ScalarToString added in v0.4.0

func ScalarToString(s kyber.Scalar) string

ScalarToString returns a hex-encoded string representation of the given scalar.

func StringToPoint added in v0.4.0

func StringToPoint(g kyber.Group, s string) (kyber.Point, error)

StringToPoint unmarshals a point in the given group from the given string.

func StringToScalar added in v0.4.0

func StringToScalar(g kyber.Group, s string) (kyber.Scalar, error)

StringToScalar unmarshals a scalar in the given group from the given string.

Types

type ByKey

type ByKey []*Identity

ByKey is simply an interface to sort lexig

func (ByKey) Len

func (b ByKey) Len() int

func (ByKey) Less

func (b ByKey) Less(i, j int) bool

func (ByKey) Swap

func (b ByKey) Swap(i, j int)

type DistPublic

type DistPublic struct {
	Coefficients []kyber.Point
}

DistPublic represents the distributed public key generated during a DKG. This is the information that can be safely exported to end users verifying a drand signature. It is the list of all commitments of the coefficients of the private distributed polynomial.

func (*DistPublic) Equal added in v0.5.2

func (d *DistPublic) Equal(d2 *DistPublic) bool

Equal returns if all coefficients of the public key d are equal to those of d2

func (*DistPublic) FromTOML

func (d *DistPublic) FromTOML(i interface{}) error

FromTOML initializes d from the TOML-compatible version of a DistPublic

func (*DistPublic) Hash added in v0.9.0

func (d *DistPublic) Hash() []byte

Hash computes the hash of this distributed key.

func (*DistPublic) Key

func (d *DistPublic) Key() kyber.Point

Key returns the first coefficient as representing the public key to be used to verify signatures issued by the distributed key.

func (*DistPublic) PubPoly added in v0.7.7

func (d *DistPublic) PubPoly() *share.PubPoly

PubPoly provides the public polynomial commitment

func (*DistPublic) TOML

func (d *DistPublic) TOML() interface{}

TOML returns a TOML-compatible version of d

func (*DistPublic) TOMLValue

func (d *DistPublic) TOMLValue() interface{}

TOMLValue returns an empty TOML-compatible dist public interface

type DistPublicTOML

type DistPublicTOML struct {
	Coefficients []string
}

DistPublicTOML is a TOML compatible value of a DistPublic

type Group

type Group struct {
	// Threshold to setup during the DKG or resharing protocol.
	Threshold int
	// Period to use for the beacon randomness generation
	Period time.Duration
	// CatchupPeriod is a delay to insert while in a catchup mode
	// also can be thought of as the minimum period allowed between
	// beacon and subsequent partial generation
	CatchupPeriod time.Duration
	// List of nodes forming this group
	Nodes []*Node
	// Time at which the first round of the chain is mined
	GenesisTime int64
	// Seed of the genesis block. When doing a DKG from scratch, it will be
	// populated directly from the list of nodes and other parameters. WHen
	// doing a resharing, this seed is taken from the first group of the
	// network.
	GenesisSeed []byte
	// In case of a resharing, this is the time at which the network will
	// transition from the old network to the new network.
	TransitionTime int64
	// The distributed public key of this group. It is nil if the group has not
	// ran a DKG protocol yet.
	PublicKey *DistPublic
}

Group holds all information about a group of drand nodes.

func GroupFromProto added in v0.9.0

func GroupFromProto(g *proto.GroupPacket) (*Group, error)

GroupFromProto convertes a protobuf group into a local Group object

func LoadGroup added in v0.4.0

func LoadGroup(list []*Node, genesis int64, public *DistPublic, period time.Duration, transition int64) *Group

LoadGroup returns a group that contains all information with respect to a QUALified set of nodes that ran successfully a setup or reshare phase. The threshold is automatically guessed from the length of the distributed key. Note: only used in tests

func NewGroup

func NewGroup(list []*Identity, threshold int, genesis int64, period, catchupPeriod time.Duration) *Group

NewGroup returns a group from the given information to be used as a new group in a setup or resharing phase. Every identity is map to a Node struct whose index is the position in the list of identity.

func (*Group) DKGNodes added in v0.9.0

func (g *Group) DKGNodes() []dkg.Node

DKGNodes return the slice of nodes of this group that is consumable by the dkg library: only the public key and index are used.

func (*Group) Equal added in v0.7.1

func (g *Group) Equal(g2 *Group) bool

Equal indicates if two groups are equal

func (*Group) Find added in v0.9.0

func (g *Group) Find(pub *Identity) *Node

Find returns the Node that is equal to the given identity (without the index). If the node is not found, Find returns nil.

func (*Group) FromTOML

func (g *Group) FromTOML(i interface{}) (err error)

FromTOML decodes the group from the toml struct

func (*Group) GetGenesisSeed added in v0.6.1

func (g *Group) GetGenesisSeed() []byte

GetGenesisSeed exposes the hash of the genesis seed for the group

func (*Group) Hash added in v0.4.0

func (g *Group) Hash() []byte

Hash provides a compact hash of a group

func (*Group) Len

func (g *Group) Len() int

Len returns the number of participants in the group

func (*Group) Node added in v0.9.0

func (g *Group) Node(i Index) *Node

Node returns the node at the given index if it exists in the group. If it does not, Node() returns nil.

func (*Group) Points

func (g *Group) Points() []kyber.Point

Points returns itself under the form of a list of kyber.Point

func (*Group) String added in v0.5.2

func (g *Group) String() string

func (*Group) TOML

func (g *Group) TOML() interface{}

TOML returns a TOML-encodable version of the Group

func (*Group) TOMLValue

func (g *Group) TOMLValue() interface{}

TOMLValue returns an empty TOML-compatible value of the group

func (*Group) ToProto added in v0.9.0

func (g *Group) ToProto() *proto.GroupPacket

ToProto encodes a local group object into its wire format

func (*Group) UnsignedIdentities added in v1.0.0

func (g *Group) UnsignedIdentities() []*Node

UnsignedIdentities return true if all identities in the group are signed correctly or not. This method is here because of backward compatibility where identities were not self-signed before.

type GroupTOML

type GroupTOML struct {
	Threshold      int
	Period         string
	CatchupPeriod  string
	Nodes          []*NodeTOML
	GenesisTime    int64
	TransitionTime int64           `toml:",omitempty"`
	GenesisSeed    string          `toml:",omitempty"`
	PublicKey      *DistPublicTOML `toml:",omitempty"`
}

GroupTOML is the representation of a Group TOML compatible

type Identity

type Identity struct {
	Key       kyber.Point
	Addr      string
	TLS       bool
	Signature []byte
}

Identity holds the corresponding public key of a Private. It also includes a valid internet facing ipv4 address where to this reach the node holding the public / private key pair.

func IdentityFromProto added in v0.9.0

func IdentityFromProto(n *proto.Identity) (*Identity, error)

IdentityFromProto creates an identity from its wire representation and verifies it validity.

func (*Identity) Address

func (i *Identity) Address() string

Address implements the net.Peer interface

func (*Identity) Equal

func (i *Identity) Equal(i2 *Identity) bool

Equal indicates if two identities are equal

func (*Identity) FromTOML

func (i *Identity) FromTOML(t interface{}) error

FromTOML loads reads the TOML description of the public key

func (*Identity) Hash added in v1.0.0

func (i *Identity) Hash() []byte

Hash returns the hash of the public key without signing the signature. The hash is the input to the signature scheme. It does _not_ hash the address & tls field as those may need to change while the node keeps the same key.

func (*Identity) IsTLS added in v0.3.7

func (i *Identity) IsTLS() bool

IsTLS returns true if this address is reachable over TLS.

func (*Identity) String added in v0.7.1

func (i *Identity) String() string

func (*Identity) TOML

func (i *Identity) TOML() interface{}

TOML returns a empty TOML-compatible version of the public key

func (*Identity) TOMLValue

func (i *Identity) TOMLValue() interface{}

TOMLValue returns a TOML-compatible interface value

func (*Identity) ToProto added in v1.0.0

func (i *Identity) ToProto() *proto.Identity

ToProto marshals an identity into protobuf format

func (*Identity) ValidSignature added in v1.0.0

func (i *Identity) ValidSignature() error

ValidSignature returns true if the signature included in this identity is correct or not

type Index added in v0.9.0

type Index = dkg.Index

Index is the index of the node

type Node added in v0.9.0

type Node struct {
	*Identity
	Index Index
}

Node is a wrapper around identity that additionally includes the index that the node has within this group. The index is computed initially when the group is first created. The index is useful only for drand nodes, and shouldn't be taken into account from an external point of view. The index is useful to be able to reshare correctly, and gives the ability to have a better logging: packets sent during DKG only contain an index, from which we can derive the actual address from the index.

func NodeFromProto added in v0.9.0

func NodeFromProto(n *proto.Node) (*Node, error)

NodeFromProto creates a node from its wire representation

func (*Node) Equal added in v0.9.0

func (n *Node) Equal(n2 *Node) bool

Equal indicates if two nodes are equal

func (*Node) FromTOML added in v0.9.0

func (n *Node) FromTOML(t interface{}) error

FromTOML unmarshals a node from TOML representation

func (*Node) Hash added in v0.9.0

func (n *Node) Hash() []byte

Hash is a compact representation of the node

func (*Node) TOML added in v0.9.0

func (n *Node) TOML() interface{}

TOML is a toml representation of the node

func (*Node) TOMLValue added in v0.9.0

func (n *Node) TOMLValue() interface{}

TOMLValue is used in marshaling

type NodeTOML added in v0.9.0

type NodeTOML struct {
	*PublicTOML
	Index Index
}

NodeTOML is the node's toml representation

type Pair added in v0.3.6

type Pair struct {
	Key    kyber.Scalar
	Public *Identity
}

Pair is a wrapper around a random scalar and the corresponding public key

func NewKeyPair

func NewKeyPair(address string) *Pair

NewKeyPair returns a freshly created private / public key pair. The group is decided by the group variable by default.

func NewTLSKeyPair added in v0.3.7

func NewTLSKeyPair(address string) *Pair

NewTLSKeyPair returns a fresh keypair associated with the given address reachable over TLS.

func (*Pair) FromTOML added in v0.3.6

func (p *Pair) FromTOML(i interface{}) error

FromTOML constructs the private key from an unmarshalled structure from TOML

func (*Pair) SelfSign added in v1.0.0

func (p *Pair) SelfSign()

SelfSign signs the public key with the key pair

func (*Pair) TOML added in v0.3.6

func (p *Pair) TOML() interface{}

TOML returns a struct that can be marshaled using a TOML-encoding library

func (*Pair) TOMLValue added in v0.3.6

func (p *Pair) TOMLValue() interface{}

TOMLValue returns an empty TOML-compatible interface value

type PairTOML added in v0.3.6

type PairTOML struct {
	Key string
}

PairTOML is the TOML-able version of a private key

type PublicTOML

type PublicTOML struct {
	Address   string
	Key       string
	TLS       bool
	Signature string
}

PublicTOML is the TOML-able version of a public key

type ResetOption added in v0.5.2

type ResetOption int

ResetOption is an option to allow for fine-grained reset operations XXX TODO

type Share

type Share dkg.DistKeyShare

Share represents the private information that a node holds after a successful DKG. This information MUST stay private !

func (*Share) FromTOML

func (s *Share) FromTOML(i interface{}) error

FromTOML initializes the share from the given TOML-compatible share interface

func (*Share) PrivateShare added in v0.5.2

func (s *Share) PrivateShare() *share.PriShare

PrivateShare returns the private share used to produce a partial signature

func (*Share) PubPoly added in v0.5.2

func (s *Share) PubPoly() *share.PubPoly

PubPoly returns the public polynomial that can be used to verify any individual patial signature

func (*Share) Public

func (s *Share) Public() *DistPublic

Public returns the distributed public key associated with the distributed key share

func (*Share) TOML

func (s *Share) TOML() interface{}

TOML returns a TOML-compatible version of this share

func (*Share) TOMLValue

func (s *Share) TOMLValue() interface{}

TOMLValue returns an empty TOML compatible interface of that Share

type ShareTOML

type ShareTOML struct {
	// index of the share.
	Index int
	// evaluation of the private polynomial.
	Share string
	// coefficients of the public polynomial.
	Commits []string
	// coefficients of the individual private polynomial generated by the node
	// at the given index.
	PrivatePoly []string
}

ShareTOML is the TOML representation of a dkg.DistKeyShare

type Store

type Store interface {
	// SaveKeyPair saves the private key generated by drand as well as the
	// public identity key associated
	SaveKeyPair(p *Pair) error
	// LoadKeyPair loads the private/public key pair associated with the drand
	// operator
	LoadKeyPair() (*Pair, error)
	SaveShare(share *Share) error
	LoadShare() (*Share, error)
	SaveGroup(*Group) error
	LoadGroup() (*Group, error)
	Reset(...ResetOption) error
}

Store abstracts the loading and saving of any private/public cryptographic material to be used by drand. For the moment, only a file based store is implemented.

func NewFileStore

func NewFileStore(baseFolder string) Store

NewFileStore is used to create the config folder and all the subfolders. If a folder alredy exists, we simply check the rights

type Tomler

type Tomler interface {
	TOML() interface{}
	FromTOML(i interface{}) error
	TOMLValue() interface{}
}

Tomler represents any struct that can be (un)marshaled into/from toml format XXX surely golang reflect package can automatically return the TOMLValue() for us

Jump to

Keyboard shortcuts

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