Documentation ¶
Index ¶
- func PollingWatcher(ctx context.Context, c Client, chainInfo *chain.Info, l log.Logger) <-chan Result
- type Cache
- type Client
- type LoggingClient
- type Option
- func From(c ...Client) Option
- func Insecurely() Option
- func WithAutoWatch() Option
- func WithCacheSize(size int) Option
- func WithChainHash(chainHash []byte) Option
- func WithChainInfo(chainInfo *chain.Info) Option
- func WithFullChainVerification() Option
- func WithLogger(l log.Logger) Option
- func WithPrometheus(r prometheus.Registerer) Option
- func WithVerifiedResult(result Result) Option
- func WithWatcher(wc WatcherCtor) Option
- type RandomData
- type Result
- type Watcher
- type WatcherCtor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶ added in v1.0.0
type Cache interface { // TryGet provides a round beacon or nil if it is not cached. TryGet(round uint64) Result // Add adds an item to the cache Add(uint64, Result) }
Cache provides a mechanism to check for rounds in the cache.
type Client ¶
type Client interface { // Get returns a the randomness at `round` or an error. // Requesting round = 0 will return randomness for the most // recent known round, bounded at a minimum to the `RoundAt(time.Now())` Get(ctx context.Context, round uint64) (Result, error) // Watch returns new randomness as it becomes available. Watch(ctx context.Context) <-chan Result // Info returns the parameters of the chain this client is connected to. // The public key, when it started, and how frequently it updates. Info(ctx context.Context) (*chain.Info, error) // RoundAt will return the most recent round of randomness that will be available // at time for the current client. RoundAt(time time.Time) uint64 // Close will halt the client, any background processes it runs and any // in-flight Get, Watch or Info requests. Behavior for usage of the client // after Close is called is undefined. io.Closer }
Client represents the drand Client interface.
func EmptyClientWithInfo ¶ added in v1.0.0
EmptyClientWithInfo makes a client that returns the given info but no randomness
func NewCachingClient ¶
NewCachingClient is a meta client that stores an LRU cache of recently fetched random values.
type LoggingClient ¶ added in v1.0.0
LoggingClient sets the logger for use by clients that suppport it
type Option ¶
type Option func(cfg *clientConfig) error
Option is an option configuring a client.
func Insecurely ¶ added in v1.0.0
func Insecurely() Option
Insecurely indicates the client should be allowed to provide randomness when the root of trust is not fully provided in a validate-able way.
func WithAutoWatch ¶ added in v1.0.0
func WithAutoWatch() Option
WithAutoWatch causes the client to automatically attempt to get randomness for rounds, so that it will hopefully already be cached when `Get` is called.
func WithCacheSize ¶
WithCacheSize specifies how large of a cache of randomness values should be kept locally. Default 32
func WithChainHash ¶ added in v1.0.0
WithChainHash configures the client to root trust with a given randomness chain hash, the chain parameters will be fetched from an HTTP endpoint.
func WithChainInfo ¶ added in v1.0.0
WithChainInfo configures the client to root trust in the given randomness chain information
func WithFullChainVerification ¶ added in v1.0.0
func WithFullChainVerification() Option
WithFullChainVerification validates random beacons not just as being generated correctly from the group signature, but ensures that the full chain is deterministic by making sure each round is derived correctly from the previous one. In cases of compromise where a single party learns sufficient shares to derive the full key, malicious randomness could otherwise be generated that is signed, but not properly derived from previous rounds according to protocol.
func WithLogger ¶
WithLogger overrides the logging options for the client, allowing specification of additional tags, or redirection / configuration of logging level and output.
func WithPrometheus ¶ added in v1.0.0
func WithPrometheus(r prometheus.Registerer) Option
WithPrometheus specifies a registry into which to report metrics
func WithVerifiedResult ¶ added in v1.0.0
WithVerifiedResult provides a checkpoint of randomness verified at a given round. Used in combination with `VerifyFullChain`, this allows for catching up only on previously not-yet-verified results.
func WithWatcher ¶ added in v1.0.0
func WithWatcher(wc WatcherCtor) Option
WithWatcher specifies a channel that can provide notifications of new randomness bootstrappeed from the chain info.
type RandomData ¶
type RandomData struct { Rnd uint64 `json:"round,omitempty"` Random []byte `json:"randomness,omitempty"` Sig []byte `json:"signature,omitempty"` PreviousSignature []byte `json:"previous_signature,omitempty"` }
RandomData holds the full random response from the server, including data needed for validation.
func (*RandomData) Randomness ¶
func (r *RandomData) Randomness() []byte
Randomness exports the randomness
func (*RandomData) Round ¶
func (r *RandomData) Round() uint64
Round provides access to the round associatted with this random data.
func (*RandomData) Signature ¶
func (r *RandomData) Signature() []byte
Signature provides the signature over this round's randomness