diff options
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/crypto/dkg/utils.go')
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus/core/crypto/dkg/utils.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/crypto/dkg/utils.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/crypto/dkg/utils.go index fa4ad9f05..9e470f0cf 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/crypto/dkg/utils.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/crypto/dkg/utils.go @@ -18,7 +18,9 @@ package dkg import ( + "encoding/binary" "fmt" + "math/rand" "github.com/dexon-foundation/bls/ffi/go/bls" @@ -69,3 +71,22 @@ func RecoverGroupPublicKey(pubShares []*PublicKeyShares) *PublicKey { } return pub } + +// NewRandomPrivateKeyShares constructs a private key shares randomly. +func NewRandomPrivateKeyShares() *PrivateKeyShares { + // Generate IDs. + rndIDs := make(IDs, 0, 10) + for i := range rndIDs { + id := make([]byte, 8) + binary.LittleEndian.PutUint64(id, rand.Uint64()) + rndIDs[i] = NewID(id) + } + prvShares := NewEmptyPrivateKeyShares() + prvShares.SetParticipants(rndIDs) + for _, id := range rndIDs { + if err := prvShares.AddShare(id, NewPrivateKey()); err != nil { + panic(err) + } + } + return prvShares +} |