github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/state/protocol/inmem/dkg.go (about)

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