forked from coinbase/kryptology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
participant.go
65 lines (57 loc) · 1.8 KB
/
participant.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
// Package frost is an implementation of the DKG part of https://eprint.iacr.org/2020/852.pdf
package frost
import (
"strconv"
"github.com/coinbase/kryptology/internal"
"github.com/coinbase/kryptology/pkg/core/curves"
"github.com/coinbase/kryptology/pkg/sharing"
)
type DkgParticipant struct {
round int
Curve *curves.Curve
otherParticipantShares map[uint32]*dkgParticipantData
Id uint32
SkShare curves.Scalar
VerificationKey curves.Point
VkShare curves.Point
feldman *sharing.Feldman
verifiers *sharing.FeldmanVerifier
secretShares []*sharing.ShamirShare
ctx byte
}
type dkgParticipantData struct {
Id uint32
Share *sharing.ShamirShare
Verifiers *sharing.FeldmanVerifier
}
func NewDkgParticipant(id, threshold uint32, ctx string, curve *curves.Curve, otherParticipants ...uint32) (*DkgParticipant, error) {
if curve == nil || len(otherParticipants) == 0 {
return nil, internal.ErrNilArguments
}
limit := uint32(len(otherParticipants)) + 1
feldman, err := sharing.NewFeldman(threshold, limit, curve)
if err != nil {
return nil, err
}
otherParticipantShares := make(map[uint32]*dkgParticipantData, len(otherParticipants))
for _, id := range otherParticipants {
otherParticipantShares[id] = &dkgParticipantData{
Id: id,
}
}
// SetBigInt the common fixed string
ctxV, _ := strconv.Atoi(ctx)
return &DkgParticipant{
Id: id,
round: 1,
Curve: curve,
feldman: feldman,
otherParticipantShares: otherParticipantShares,
ctx: byte(ctxV),
}, nil
}