-
Notifications
You must be signed in to change notification settings - Fork 179
/
dkg.go
36 lines (30 loc) · 1.08 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
35
36
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
}
var _ protocol.DKG = (*DKG)(nil)
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
}