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