Version: v1.4.6 Latest Latest

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

Go to latest
Published: Sep 30, 2022 License: Apache-2.0, MIT Imports: 16 Imported by: 8




View Source
const TimeOfRoundErrorValue = math.MaxInt64 - maxTimeBuffer

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


This section is empty.


func CurrentRound

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

CurrentRound calculates the active round at `now`

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


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 added in v1.0.2

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"`
	ID          string        `json:"id"`
	Period      time.Duration `json:"period"`
	Scheme      scheme.Scheme `json:"scheme"`
	GenesisTime int64         `json:"genesis_time"`
	GenesisSeed []byte        `json:"group_hash"`

Info represents the public information that is necessary for a client to verify 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) HashString added in v1.4.6

func (c *Info) HashString() string

HashString returns the value of Hash in string format

func (*Info) ToJSON

func (c *Info) ToJSON(w io.Writer, metadata *common.Metadata) error

ToJSON provides a json serialization of an info packet

func (*Info) ToProto

func (c *Info) ToProto(metadata *common.Metadata) *drand.ChainInfoPacket

ToProto returns the protobuf description of the chain info

func (*Info) Verifier added in v1.4.6

func (c *Info) Verifier() *Verifier

Verifier returns the verifier used to verify the beacon produced by this chain

type Store

type Store interface {
	Len() int
	Put(*Beacon) error
	Last() (*Beacon, error)
	Get(round uint64) (*Beacon, error)
	Del(round uint64) error
	SaveTo(w io.Writer) error

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

type Verifier added in v1.4.6

type Verifier struct {
	// contains filtered or unexported fields

Verifier allows verifying the beacons signature based on a scheme.

func NewVerifier added in v1.4.6

func NewVerifier(sch scheme.Scheme) *Verifier

func (Verifier) DigestMessage added in v1.4.6

func (v Verifier) DigestMessage(currRound uint64, prevSig []byte) []byte

DigestMessage returns a slice of bytes as the message to sign or to verify alongside a beacon signature.

func (Verifier) IsPrevSigMeaningful added in v1.4.6

func (v Verifier) IsPrevSigMeaningful() bool

func (Verifier) VerifyBeacon added in v1.4.6

func (v Verifier) VerifyBeacon(b Beacon, pubkey kyber.Point) 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.


Path Synopsis

Jump to

Keyboard shortcuts

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