github.com/koko1123/flow-go-1@v0.29.6/state/protocol/inmem/dkg.go (about)

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