Documentation ¶
Index ¶
- Constants
- Variables
- func CollectiveBeaconReceived(handler interface{}, params ...interface{})
- func ExtractRandomness(signature []byte) ([]byte, error)
- func ProcessBeacon(state *State, cb *CollectiveBeaconEvent) error
- func ResolveNextTimePoint(nowTime, interval time.Duration) time.Duration
- func VerifyCollectiveBeacon(state *State, cb *CollectiveBeaconEvent) error
- type CollectiveBeaconEvent
- type CollectiveBeaconPayload
- func CollectiveBeaconPayloadFromBytes(bytes []byte) (result *CollectiveBeaconPayload, consumedBytes int, err error)
- func CollectiveBeaconPayloadFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (*CollectiveBeaconPayload, error)
- func NewCollectiveBeaconPayload(instanceID uint32, round uint64, prevSignature, signature, dpk []byte) *CollectiveBeaconPayload
- func (p *CollectiveBeaconPayload) Bytes() (bytes []byte)
- func (p *CollectiveBeaconPayload) Decode(b []byte) (bytesRead int, err error)
- func (p *CollectiveBeaconPayload) Encode() ([]byte, error)
- func (p *CollectiveBeaconPayload) Marshal() (bytes []byte, err error)
- func (p *CollectiveBeaconPayload) String() string
- func (p *CollectiveBeaconPayload) Type() payload.Type
- type Committee
- type DRNG
- type Event
- type Header
- type Option
- type Options
- type Randomness
- type State
- type Ticker
- type Type
Constants ¶
const ( // SignatureSize defines the BLS Signature size in bytes. SignatureSize = 96 // PublicKeySize defines the BLS Public Key size in bytes. PublicKeySize = 48 )
const HeaderLength = 5
HeaderLength defines the length of a DRNG header
const (
// ObjectName defines the name of the dRNG object.
ObjectName = "dRNG"
)
Variables ¶
var ( // ErrDistributedPubKeyMismatch is returned if the distributed public key does not match. ErrDistributedPubKeyMismatch = errors.New("Distributed Public Key does not match") // ErrInvalidRound is returned if the round is invalid. ErrInvalidRound = errors.New("Invalid Round") // ErrInstanceIDMismatch is returned if the instanceID does not match. ErrInstanceIDMismatch = errors.New("InstanceID does not match") // ErrInvalidIssuer is returned if the issuer is invalid. ErrInvalidIssuer = errors.New("Invalid Issuer") // ErrNilState is returned on nil state. ErrNilState = errors.New("Nil state") // ErrNilData is returned on nil data. ErrNilData = errors.New("Nil data") )
var PayloadType = payload.NewType(111, ObjectName)
PayloadType defines the type of the drng payload.
Functions ¶
func CollectiveBeaconReceived ¶
func CollectiveBeaconReceived(handler interface{}, params ...interface{})
CollectiveBeaconReceived returns the data of a collective beacon event.
func ExtractRandomness ¶
ExtractRandomness returns the randomness from a given signature.
func ProcessBeacon ¶
func ProcessBeacon(state *State, cb *CollectiveBeaconEvent) error
ProcessBeacon performs the following tasks: - verify that we have a valid random - update drng state
func ResolveNextTimePoint ¶ added in v0.5.8
ResolveNextTimePoint returns the next time point.
func VerifyCollectiveBeacon ¶
func VerifyCollectiveBeacon(state *State, cb *CollectiveBeaconEvent) error
VerifyCollectiveBeacon verifies against a given state that the given CollectiveBeaconEvent contains a valid beacon.
Types ¶
type CollectiveBeaconEvent ¶
type CollectiveBeaconEvent struct { // Public key of the issuer. IssuerPublicKey ed25519.PublicKey // Timestamp when the beacon was issued. Timestamp time.Time // InstanceID of the beacon. InstanceID uint32 // Round of the current beacon. Round uint64 // Collective signature of the previous beacon. PrevSignature []byte // Collective signature of the current beacon. Signature []byte // The distributed public key. Dpk []byte }
CollectiveBeaconEvent holds data about a collective beacon event.
type CollectiveBeaconPayload ¶
type CollectiveBeaconPayload struct { Header // Round of the current beacon Round uint64 // Collective signature of the previous beacon PrevSignature []byte // Collective signature of the current beacon Signature []byte // The distributed public key Dpk []byte // contains filtered or unexported fields }
CollectiveBeaconPayload is a collective beacon payload.
func CollectiveBeaconPayloadFromBytes ¶
func CollectiveBeaconPayloadFromBytes(bytes []byte) (result *CollectiveBeaconPayload, consumedBytes int, err error)
CollectiveBeaconPayloadFromBytes parses the marshaled version of a Payload into an object. It either returns a new Payload or fills an optionally provided Payload with the parsed information.
func CollectiveBeaconPayloadFromMarshalUtil ¶
func CollectiveBeaconPayloadFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (*CollectiveBeaconPayload, error)
CollectiveBeaconPayloadFromMarshalUtil is a wrapper for simplified unmarshaling in a byte stream using the marshalUtil package.
func NewCollectiveBeaconPayload ¶
func NewCollectiveBeaconPayload(instanceID uint32, round uint64, prevSignature, signature, dpk []byte) *CollectiveBeaconPayload
NewCollectiveBeaconPayload creates a new collective beacon payload.
func (*CollectiveBeaconPayload) Bytes ¶
func (p *CollectiveBeaconPayload) Bytes() (bytes []byte)
Bytes returns the collective beacon payload bytes.
func (*CollectiveBeaconPayload) Decode ¶ added in v0.8.13
func (p *CollectiveBeaconPayload) Decode(b []byte) (bytesRead int, err error)
Decode deserializes bytes into a valid object.
func (*CollectiveBeaconPayload) Encode ¶ added in v0.8.13
func (p *CollectiveBeaconPayload) Encode() ([]byte, error)
Encode returns a serialized byte slice of the object.
func (*CollectiveBeaconPayload) Marshal ¶
func (p *CollectiveBeaconPayload) Marshal() (bytes []byte, err error)
Marshal marshals the collective beacon payload into bytes.
func (*CollectiveBeaconPayload) String ¶
func (p *CollectiveBeaconPayload) String() string
func (*CollectiveBeaconPayload) Type ¶
func (p *CollectiveBeaconPayload) Type() payload.Type
Type returns the collective beacon payload type.
type Committee ¶
type Committee struct { // InstanceID holds the identifier of the dRAND instance. InstanceID uint32 // Threshold holds the threshold of the secret sharing protocol. Threshold uint8 // Identities holds the nodes' identities of the committee members. Identities []ed25519.PublicKey // DistributedPK holds the drand distributed public key. DistributedPK []byte }
Committee defines the current committee state of a DRNG instance.
type DRNG ¶
type DRNG struct { State map[uint32]*State // The state of the DRNG. Events *Event // The events fired on the DRNG. }
DRNG holds the state and events of a drng instance.
type Event ¶
type Event struct { // Collective Beacon is triggered each time we receive a new CollectiveBeacon message. CollectiveBeacon *events.Event // Randomness is triggered each time we receive a new and valid CollectiveBeacon message. Randomness *events.Event }
Event holds the different events triggered by a DRNG instance.
type Header ¶
type Header struct { PayloadType Type // message type InstanceID uint32 // identifier of the DRNG instance }
Header defines defines a DRNG payload header
func HeaderFromBytes ¶
func HeaderFromBytes(bytes []byte, optionalTargetObject ...*Header) (result Header, consumedBytes int, err error)
HeaderFromBytes unmarshals a header from a sequence of bytes. It either creates a new header or fills the optionally provided object with the parsed information.
func HeaderFromMarshalUtil ¶
func HeaderFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (Header, error)
HeaderFromMarshalUtil is a wrapper for simplified unmarshaling in a byte stream using the marshalUtil package.
type Option ¶
type Option func(*Options)
Option is a function which sets the given option.
func SetRandomness ¶
func SetRandomness(r *Randomness) Option
SetRandomness sets the initial randomness
type Options ¶
type Options struct { // The initial committee of the DRNG. Committee *Committee // The initial randomness of the DRNG. Randomness *Randomness }
Options define state options of a DRNG.
type Randomness ¶
type Randomness struct { // Round holds the current DRNG round. Round uint64 // Randomness holds the current randomness as a slice of bytes. Randomness []byte // Timestamp holds the timestamp of the current randomness message Timestamp time.Time }
Randomness defines the current randomness state of a DRNG instance.
func (Randomness) Float64 ¶
func (r Randomness) Float64() float64
Float64 returns a float64 [0.0,1.0) representation of the randomness byte slice.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State represents the state of the DRNG.
func (*State) Randomness ¶
func (s *State) Randomness() Randomness
Randomness returns the randomness of the DRNG state
func (*State) UpdateCommittee ¶
UpdateCommittee updates the committee of the DRNG state
func (*State) UpdateRandomness ¶
func (s *State) UpdateRandomness(r *Randomness)
UpdateRandomness updates the randomness of the DRNG state
type Ticker ¶ added in v0.5.8
type Ticker struct {
// contains filtered or unexported fields
}
Ticker holds a channel that delivers randomness at intervals.
func NewTicker ¶ added in v0.5.8
func NewTicker(dRNGState func() *State, interval time.Duration, defaultValue float64, awaitOffset time.Duration) *Ticker
NewTicker returns a pointer to a new Ticker.
func (*Ticker) C ¶ added in v0.5.8
C returns the channel from which random generated numbers can be consumed from.
func (*Ticker) DelayedRoundStart ¶ added in v0.5.8
DelayedRoundStart returns how much the current Round is delayed already.
func (*Ticker) UpdateRandomness ¶ added in v0.5.8
func (t *Ticker) UpdateRandomness(r Randomness)
UpdateRandomness updates the randomness of the ticker.