core

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: May 16, 2018 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBeaconPeriod time.Duration = 1 * time.Minute

DefaultBeaconPeriod is the period in which the beacon logic creates new random beacon.

View Source
const DefaultConfigFolder = ".drand"

DefaultConfigFolder is the name of the folder containing all key materials (and the beacons db file by default). It is relative to the user's home directory.

View Source
const DefaultDbFolder = "db"

DefaultDbFolder is the name of the folder in which the db file is saved. By default it is relative to the DefaultConfigFolder path.

Variables

View Source
var DefaultHash = sha256.New
View Source
var DefaultSeed = []byte("Truth is like the sun. You can shut it out for a time, but it ain't goin' away.")

Functions

func Decrypt

func Decrypt(g kyber.Group, fn func() hash.Hash, priv kyber.Scalar, o *drand.ECIESObject) ([]byte, error)

Decrypts does almost the same as Encrypt: the ephemereal static DH exchange, and the derivation of the symmetric key. It finally tries to decrypt the ciphertext and returns the plaintext if successful, an error otherwise.

func Encrypt

func Encrypt(g kyber.Group, fn func() hash.Hash, public kyber.Point, msg []byte) (*drand.ECIESObject, error)

Encrypts performs a ephemereal-static DH exchange, creates the shared key from it using a KDF scheme (hkdf from Go at the time of writing) and then computes the ciphertext using a AEAD scheme (AES-GCM from Go at the time of writing). This methods returns the ephemeral point of the DH exchange, the ciphertext and the associated nonce. It returns an error if something went wrong during the encryption.

Types

type Client

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

Client is the endpoint logic, communicating with drand servers

func NewClient

func NewClient(opts ...grpc.DialOption) *Client

NewClient returns a Client able to talk to drand instances

func (*Client) LastPublic

func (c *Client) LastPublic(addr string, pub *key.DistPublic) (*drand.PublicRandResponse, error)

LastPublic returns the last randomness beacon from the server associated. It returns it if the randomness is valid.

func (*Client) Private

func (c *Client) Private(id *key.Identity) ([]byte, error)

Private retrieves a private random value from the server. It does that by generating an ephemeral key pair, sends it encrypted to the remote server, and decrypts the response, the randomness.

type Config

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

func NewConfig

func NewConfig(opts ...ConfigOption) *Config

NewConfig returns the config to pass to drand with the default options set and the updated values given by the options.

func (*Config) ConfigFolder

func (d *Config) ConfigFolder() string

func (*Config) DBFolder

func (d *Config) DBFolder() string

func (*Config) ListenAddress

func (d *Config) ListenAddress(defaultAddr string) string

ListenAddress returns the given default address or the listen address stored in the config thanks to WithListenAddress

type ConfigOption

type ConfigOption func(*Config)

func WithBeaconCallback

func WithBeaconCallback(fn func(*beacon.Beacon)) ConfigOption

func WithBeaconPeriod

func WithBeaconPeriod(period time.Duration) ConfigOption

func WithBoltOptions

func WithBoltOptions(opts *bolt.Options) ConfigOption

func WithConfigFolder

func WithConfigFolder(folder string) ConfigOption

func WithDbFolder

func WithDbFolder(folder string) ConfigOption

WithDbFolder sets the path folder for the db file. This path is NOT relative to the DrandFolder path if set.

func WithDkgTimeout

func WithDkgTimeout(t time.Duration) ConfigOption

func WithGrpcOptions

func WithGrpcOptions(opts ...grpc.DialOption) ConfigOption

func WithListenAddress

func WithListenAddress(addr string) ConfigOption

WithListenAddress specifies the address the drand instance should bind to. It is useful if you want to advertise a public proxy address and the drand instance runs behind your network.

type Drand

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

Drand is the main logic of the program. It reads the keys / group file, it can start the DKG, read/write shars to files and can initiate/respond to TBlS signature requests.

func LoadDrand

func LoadDrand(s key.Store, c *Config) (*Drand, error)

LoadDrand restores a drand instance as it was running after a DKG instance

func NewDrand

func NewDrand(s key.Store, g *key.Group, c *Config) (*Drand, error)

NewDrand returns an drand struct that is ready to start the DKG protocol with the given group and then to serve randomness. It assumes the private key pair has been generated already.

func (*Drand) BeaconLoop

func (d *Drand) BeaconLoop()

BeaconLoop starts periodically the TBLS protocol. The seed is the first message signed alongside with the current timestamp. All subsequent signatures are chained: s_i+1 = SIG(s_i || timestamp) For the moment, each resulting signature is stored in a file named beacons/<timestamp>.sig.

func (*Drand) NewBeacon

func (d *Drand) NewBeacon(c context.Context, in *drand.BeaconRequest) (*drand.BeaconResponse, error)

func (*Drand) Private

func (*Drand) Setup

func (*Drand) StartDKG

func (d *Drand) StartDKG() error

StartDKG starts the DKG protocol by sending the first packet of the DKG protocol to every other node in the group. It returns nil if the DKG protocol finished successfully or an error otherwise.

func (*Drand) Stop

func (d *Drand) Stop()

func (*Drand) WaitDKG

func (d *Drand) WaitDKG() error

WaitDKG waits messages from the DKG protocol started by a leader or some nodes, and then wait until completion.

Jump to

Keyboard shortcuts

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