Documentation

Index

Constants

View Source
const TimeOfRoundErrorValue = math.MaxInt64 - maxTimeBuffer

TimeOfRoundErrorValue is the value returned by `TimeOfRound` when an invalid round is specified.

Variables

This section is empty.

Functions

func CurrentRound

func CurrentRound(now int64, period time.Duration, genesis int64) uint64

CurrentRound calculates the active round at `now`

func Message

func Message(currRound uint64, prevSig []byte) []byte

Message returns a slice of bytes as the message to sign or to verify alongside a beacon signature. H ( prevSig || currRound)

func NextRound

func NextRound(now int64, period time.Duration, genesis int64) (nextRound uint64, nextTime int64)

NextRound returns the next upcoming round and its UNIX time given the genesis time and the period. round at time genesis = round 1. Round 0 is fixed.

func RandomnessFromSignature

func RandomnessFromSignature(sig []byte) []byte

RandomnessFromSignature derives the round randomness from its signature

func RoundToBytes

func RoundToBytes(r uint64) []byte

RoundToBytes serializes a round number to bytes (8 bytes fixed length big-endian).

func TimeOfRound

func TimeOfRound(period time.Duration, genesis int64, round uint64) int64

TimeOfRound is returning the time the current round should happen

func Verify

func Verify(pubkey kyber.Point, prevSig, signature []byte, round uint64) error

Verify is similar to verify beacon but doesn't require to get the full beacon structure.

func VerifyBeacon

func VerifyBeacon(pubkey kyber.Point, b *Beacon) error

VerifyBeacon returns an error if the given beacon does not verify given the public key. The public key "point" can be obtained from the `key.DistPublic.Key()` method. The distributed public is the one written in the configuration file of the network.

Types

type Beacon

type Beacon struct {
	// PreviousSig is the previous signature generated
	PreviousSig []byte
	// Round is the round number this beacon is tied to
	Round uint64
	// Signature is the BLS deterministic signature over Round || PreviousRand
	Signature []byte
}

Beacon holds the randomness as well as the info to verify it.

func GenesisBeacon

func GenesisBeacon(c *Info) *Beacon

GenesisBeacon returns the first beacon inserted in the chain

func (*Beacon) Equal

func (b *Beacon) Equal(b2 *Beacon) bool

Equal indicates if two beacons are equal

func (*Beacon) GetRound

func (b *Beacon) GetRound() uint64

GetRound provides the round of the beacon

func (*Beacon) Marshal

func (b *Beacon) Marshal() ([]byte, error)

Marshal provides a JSON encoding of a beacon

func (*Beacon) Randomness

func (b *Beacon) Randomness() []byte

Randomness returns the hashed signature. It is an example that uses sha256, but it could use blake2b for example.

func (*Beacon) String

func (b *Beacon) String() string

func (*Beacon) Unmarshal

func (b *Beacon) Unmarshal(buff []byte) error

Unmarshal decodes a beacon from JSON

type Cursor

type Cursor interface {
	First() *Beacon
	Next() *Beacon
	Seek(round uint64) *Beacon
	Last() *Beacon
}

Cursor iterates over items in sorted key order. This starts from the first key/value pair and updates the k/v variables to the next key/value on each iteration.

The loop finishes at the end of the cursor when a nil key is returned.

for k, v := c.First(); k != nil; k, v = c.Next() {
    fmt.Printf("A %s is %s.\n", k, v)
}

type Info

type Info struct {
	PublicKey   kyber.Point   `json:"public_key"`
	Period      time.Duration `json:"period"`
	GenesisTime int64         `json:"genesis_time"`
	GroupHash   []byte        `json:"group_hash"`
}

Info represents the public information that is necessary for a client to very any beacon present in a randomness chain.

func InfoFromJSON

func InfoFromJSON(buff io.Reader) (*Info, error)

InfoFromJSON returns a Info from JSON description in the given reader

func InfoFromProto

func InfoFromProto(p *drand.ChainInfoPacket) (*Info, error)

InfoFromProto returns a Info from the protocol description

func NewChainInfo

func NewChainInfo(g *key.Group) *Info

NewChainInfo makes a chain Info from a group

func (*Info) Equal

func (c *Info) Equal(c2 *Info) bool

Equal indicates if two Chain Info objects are equivalent

func (*Info) Hash

func (c *Info) Hash() []byte

Hash returns the canonical hash representing the chain information. A hash is consistent throughout the entirety of a chain, regardless of the network composition, the actual nodes, generating the randomness.

func (*Info) ToJSON

func (c *Info) ToJSON(w io.Writer) error

ToJSON provides a json serialization of an info packet

func (*Info) ToProto

func (c *Info) ToProto() *drand.ChainInfoPacket

ToProto returns the protobuf description of the chain info

type Store

type Store interface {
	Len() int
	Put(*Beacon) error
	Last() (*Beacon, error)
	Get(round uint64) (*Beacon, error)
	Cursor(func(Cursor))
	Close()
	Del(round uint64) error
}

Store is an interface to store Beacons packets where they can also be retrieved to be delivered to end clients.

Directories

Path Synopsis
beacon
boltdb