github.com/onflow/flow-go@v0.33.17/state/protocol/inmem/dkg.go (about)

     1  package inmem
     2  
     3  import (
     4  	"github.com/onflow/flow-go/crypto"
     5  	"github.com/onflow/flow-go/model/flow"
     6  	"github.com/onflow/flow-go/state/protocol"
     7  )
     8  
     9  type DKG struct {
    10  	enc EncodableDKG
    11  }
    12  
    13  var _ protocol.DKG = (*DKG)(nil)
    14  
    15  func (d DKG) Size() uint                 { return uint(len(d.enc.Participants)) }
    16  func (d DKG) GroupKey() crypto.PublicKey { return d.enc.GroupKey.PublicKey }
    17  
    18  // Index returns the index for the given node. Error Returns:
    19  // protocol.IdentityNotFoundError if nodeID is not a valid DKG participant.
    20  func (d DKG) Index(nodeID flow.Identifier) (uint, error) {
    21  	part, exists := d.enc.Participants[nodeID]
    22  	if !exists {
    23  		return 0, protocol.IdentityNotFoundError{NodeID: nodeID}
    24  	}
    25  	return part.Index, nil
    26  }
    27  
    28  // KeyShare returns the public key share for the given node. Error Returns:
    29  // protocol.IdentityNotFoundError if nodeID is not a valid DKG participant.
    30  func (d DKG) KeyShare(nodeID flow.Identifier) (crypto.PublicKey, error) {
    31  	part, exists := d.enc.Participants[nodeID]
    32  	if !exists {
    33  		return nil, protocol.IdentityNotFoundError{NodeID: nodeID}
    34  	}
    35  	return part.KeyShare, nil
    36  }