diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-12-18 10:02:30 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:54 +0800 |
commit | 1c506268a5385adce7885b7e950707bf9ffd5084 (patch) | |
tree | 20fdeb4fffc2f69e493fba1f8771441fa3db484c /vendor/github.com/dexon-foundation/dexon-consensus/core/crypto/dkg/utils.go | |
parent | c972cddcfb5d5b16efdf08135b4f7782d796764c (diff) | |
download | dexon-1c506268a5385adce7885b7e950707bf9ffd5084.tar dexon-1c506268a5385adce7885b7e950707bf9ffd5084.tar.gz dexon-1c506268a5385adce7885b7e950707bf9ffd5084.tar.bz2 dexon-1c506268a5385adce7885b7e950707bf9ffd5084.tar.lz dexon-1c506268a5385adce7885b7e950707bf9ffd5084.tar.xz dexon-1c506268a5385adce7885b7e950707bf9ffd5084.tar.zst dexon-1c506268a5385adce7885b7e950707bf9ffd5084.zip |
vendor: sync to latest core (#91)
- Implement new methods in db to cache DKG
private key.
- Implement new methods in db to cache compaction
chain tip.
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 +} |