This commit is contained in:
programmer10110 2020-08-13 19:34:38 +03:00
parent f5508c3ed9
commit 381075f652
3 changed files with 26 additions and 9 deletions

View File

@ -91,6 +91,10 @@ func (am *AirgappedMachine) handleStateAwaitParticipantsConfirmations(o *client.
err error
)
if _, ok := am.dkgInstances[o.DKGIdentifier]; ok {
return fmt.Errorf("dkg instance %s already exists", o.DKGIdentifier)
}
if err = json.Unmarshal(o.Payload, &payload); err != nil {
return fmt.Errorf("failed to unmarshal payload: %w", err)
}
@ -113,7 +117,7 @@ func (am *AirgappedMachine) GetPubKey() kyber.Point {
func (am *AirgappedMachine) handleStateDkgCommitsAwaitConfirmations(o *client.Operation) error {
var (
payload responses.DKGProposalPubKeyParticipantResponse
payload responses.SignatureProposalParticipantStatusResponse
err error
)
@ -128,10 +132,10 @@ func (am *AirgappedMachine) handleStateDkgCommitsAwaitConfirmations(o *client.Op
for _, entry := range payload {
pubKey := bn256.NewSuiteG2().Point()
if err = pubKey.UnmarshalBinary(entry.PubKey); err != nil {
if err = pubKey.UnmarshalBinary(entry.DkgPubKey); err != nil {
return fmt.Errorf("failed to unmarshal pubkey: %w", err)
}
dkgInstance.StorePubKey(entry.Title, pubKey)
dkgInstance.StorePubKey(entry.Title, entry.ParticipantId, pubKey)
}
if err = dkgInstance.InitDKGInstance(); err != nil {

View File

@ -63,13 +63,18 @@ func (d *DKG) GetParticipantByIndex(index int) string {
return d.pubkeys.GetParticipantByIndex(index)
}
func (d *DKG) StorePubKey(participant string, pk kyber.Point) bool {
func (d *DKG) GetPKByIndex(index int) kyber.Point {
return d.pubkeys.GetPKByIndex(index)
}
func (d *DKG) StorePubKey(participant string, pid int, pk kyber.Point) bool {
d.Lock()
defer d.Unlock()
return d.pubkeys.Add(&PK2Participant{
Participant: participant,
PK: pk,
Participant: participant,
PK: pk,
ParticipantID: pid,
})
}

View File

@ -6,8 +6,9 @@ import (
)
type PK2Participant struct {
Participant string
PK kyber.Point
ParticipantID int
Participant string
PK kyber.Point
}
type PKStore []*PK2Participant
@ -25,7 +26,7 @@ func (s *PKStore) Add(newPk *PK2Participant) bool {
func (s PKStore) Len() int { return len(s) }
func (s PKStore) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s PKStore) Less(i, j int) bool { return s[i].Participant < s[j].Participant }
func (s PKStore) Less(i, j int) bool { return s[i].ParticipantID < s[j].ParticipantID }
func (s PKStore) GetPKs() []kyber.Point {
var out = make([]kyber.Point, len(s))
for idx, val := range s {
@ -43,6 +44,13 @@ func (s PKStore) GetPKByParticipant(p string) (kyber.Point, error) {
return nil, fmt.Errorf("participant %s does not exist", p)
}
func (s PKStore) GetPKByIndex(index int) kyber.Point {
if index < 0 || index > len(s) {
return nil
}
return s[index].PK
}
func (s PKStore) GetParticipantByIndex(index int) string {
if index < 0 || index > len(s) {
return ""