aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-02 17:12:57 +0800
committerGitHub <noreply@github.com>2018-10-02 17:12:57 +0800
commitd34f6b070e7361fcb582350ad8faf6148e82042e (patch)
tree77a9efa5965ef16778e023b93428309e908531c7 /core
parentfb27745f2ca4eaf66f53f48740cbd148ee15bbdf (diff)
downloaddexon-consensus-d34f6b070e7361fcb582350ad8faf6148e82042e.tar
dexon-consensus-d34f6b070e7361fcb582350ad8faf6148e82042e.tar.gz
dexon-consensus-d34f6b070e7361fcb582350ad8faf6148e82042e.tar.bz2
dexon-consensus-d34f6b070e7361fcb582350ad8faf6148e82042e.tar.lz
dexon-consensus-d34f6b070e7361fcb582350ad8faf6148e82042e.tar.xz
dexon-consensus-d34f6b070e7361fcb582350ad8faf6148e82042e.tar.zst
dexon-consensus-d34f6b070e7361fcb582350ad8faf6148e82042e.zip
core: Export DKGGroupPublicKey and its verify function (#160)
Diffstat (limited to 'core')
-rw-r--r--core/configuration-chain.go8
-rw-r--r--core/dkg-tsig-protocol.go17
-rw-r--r--core/dkg-tsig-protocol_test.go14
3 files changed, 21 insertions, 18 deletions
diff --git a/core/configuration-chain.go b/core/configuration-chain.go
index 300b080..aca1a84 100644
--- a/core/configuration-chain.go
+++ b/core/configuration-chain.go
@@ -42,7 +42,7 @@ type configurationChain struct {
dkg *dkgProtocol
dkgLock sync.RWMutex
dkgSigner map[uint64]*dkgShareSecret
- gpk map[uint64]*dkgGroupPublicKey
+ gpk map[uint64]*DKGGroupPublicKey
dkgResult sync.RWMutex
tsig *tsigProtocol
tsigReady *sync.Cond
@@ -60,7 +60,7 @@ func newConfigurationChain(
recv: recv,
gov: gov,
dkgSigner: make(map[uint64]*dkgShareSecret),
- gpk: make(map[uint64]*dkgGroupPublicKey),
+ gpk: make(map[uint64]*DKGGroupPublicKey),
tsigReady: sync.NewCond(&sync.Mutex{}),
}
}
@@ -123,7 +123,7 @@ func (cc *configurationChain) runDKG(round uint64) error {
cc.dkgLock.Unlock()
<-ticker.Tick()
cc.dkgLock.Lock()
- gpk, err := newDKGGroupPublicKey(round,
+ gpk, err := NewDKGGroupPublicKey(round,
cc.gov.DKGMasterPublicKeys(round),
cc.gov.DKGComplaints(round),
cc.dkg.threshold)
@@ -170,7 +170,7 @@ func (cc *configurationChain) preparePartialSignature(
func (cc *configurationChain) runTSig(
round uint64, hash common.Hash, psigType types.DKGPartialSignatureType) (
crypto.Signature, error) {
- gpk, exist := func() (*dkgGroupPublicKey, bool) {
+ gpk, exist := func() (*DKGGroupPublicKey, bool) {
cc.dkgResult.RLock()
defer cc.dkgResult.RUnlock()
gpk, exist := cc.gpk[round]
diff --git a/core/dkg-tsig-protocol.go b/core/dkg-tsig-protocol.go
index 2bdb4e9..2bb4c52 100644
--- a/core/dkg-tsig-protocol.go
+++ b/core/dkg-tsig-protocol.go
@@ -81,7 +81,8 @@ type dkgShareSecret struct {
privateKey *dkg.PrivateKey
}
-type dkgGroupPublicKey struct {
+// DKGGroupPublicKey is the result of DKG protocol.
+type DKGGroupPublicKey struct {
round uint64
qualifyIDs dkg.IDs
qualifyNodeIDs map[types.NodeID]struct{}
@@ -92,7 +93,7 @@ type dkgGroupPublicKey struct {
}
type tsigProtocol struct {
- groupPublicKey *dkgGroupPublicKey
+ groupPublicKey *DKGGroupPublicKey
hash common.Hash
psigType types.DKGPartialSignatureType
sigs map[dkg.ID]dkg.PartialSignature
@@ -311,11 +312,12 @@ func (ss *dkgShareSecret) sign(hash common.Hash) dkg.PartialSignature {
return dkg.PartialSignature(sig)
}
-func newDKGGroupPublicKey(
+// NewDKGGroupPublicKey creats a DKGGroupPublicKey instance.
+func NewDKGGroupPublicKey(
round uint64,
mpks []*types.DKGMasterPublicKey, complaints []*types.DKGComplaint,
threshold int) (
- *dkgGroupPublicKey, error) {
+ *DKGGroupPublicKey, error) {
// Calculate qualify members.
disqualifyIDs := map[types.NodeID]struct{}{}
complaintsByID := map[types.NodeID]int{}
@@ -369,7 +371,7 @@ func newDKGGroupPublicKey(
pubShares = append(pubShares, &mpkMap[id].PublicKeyShares)
}
groupPK := dkg.RecoverGroupPublicKey(pubShares)
- return &dkgGroupPublicKey{
+ return &DKGGroupPublicKey{
round: round,
qualifyIDs: qualifyIDs,
qualifyNodeIDs: qualifyNodeIDs,
@@ -380,13 +382,14 @@ func newDKGGroupPublicKey(
}, nil
}
-func (gpk *dkgGroupPublicKey) verifySignature(
+// VerifySignature verifies if the signature is correct.
+func (gpk *DKGGroupPublicKey) VerifySignature(
hash common.Hash, sig crypto.Signature) bool {
return gpk.groupPublicKey.VerifySignature(hash, sig)
}
func newTSigProtocol(
- gpk *dkgGroupPublicKey,
+ gpk *DKGGroupPublicKey,
hash common.Hash,
psigType types.DKGPartialSignatureType) *tsigProtocol {
return &tsigProtocol{
diff --git a/core/dkg-tsig-protocol_test.go b/core/dkg-tsig-protocol_test.go
index 6273e53..1e8cac4 100644
--- a/core/dkg-tsig-protocol_test.go
+++ b/core/dkg-tsig-protocol_test.go
@@ -181,7 +181,7 @@ func (s *DKGTSIGProtocolTestSuite) TestDKGTSIGProtocol() {
}
// DKG is fininished.
- gpk, err := newDKGGroupPublicKey(round,
+ gpk, err := NewDKGGroupPublicKey(round,
gov.DKGMasterPublicKeys(round), gov.DKGComplaints(round),
k,
)
@@ -230,7 +230,7 @@ func (s *DKGTSIGProtocolTestSuite) TestDKGTSIGProtocol() {
sig, err := tsig.signature()
s.Require().NoError(err)
- s.True(gpk.verifySignature(msgHash, sig))
+ s.True(gpk.VerifySignature(msgHash, sig))
}
func (s *DKGTSIGProtocolTestSuite) TestNackComplaint() {
@@ -477,7 +477,7 @@ func (s *DKGTSIGProtocolTestSuite) TestQualifyIDs() {
s.Require().True(complaints[i].IsNack())
}
- gpk, err := newDKGGroupPublicKey(round,
+ gpk, err := NewDKGGroupPublicKey(round,
gov.DKGMasterPublicKeys(round), complaints,
k,
)
@@ -487,7 +487,7 @@ func (s *DKGTSIGProtocolTestSuite) TestQualifyIDs() {
s.NotEqual(id, byzantineID)
}
- gpk2, err := newDKGGroupPublicKey(round,
+ gpk2, err := NewDKGGroupPublicKey(round,
gov.DKGMasterPublicKeys(round), complaints[:k],
k,
)
@@ -497,7 +497,7 @@ func (s *DKGTSIGProtocolTestSuite) TestQualifyIDs() {
// Test for complaint.
complaints[0].PrivateShare.Signature = crypto.Signature{Signature: []byte{0}}
s.Require().False(complaints[0].IsNack())
- gpk3, err := newDKGGroupPublicKey(round,
+ gpk3, err := NewDKGGroupPublicKey(round,
gov.DKGMasterPublicKeys(round), complaints[:1],
k,
)
@@ -552,7 +552,7 @@ func (s *DKGTSIGProtocolTestSuite) TestPartialSignature() {
}
// DKG is fininished.
- gpk, err := newDKGGroupPublicKey(round,
+ gpk, err := NewDKGGroupPublicKey(round,
gov.DKGMasterPublicKeys(round), gov.DKGComplaints(round),
k,
)
@@ -613,7 +613,7 @@ func (s *DKGTSIGProtocolTestSuite) TestPartialSignature() {
sig, err := tsig.signature()
s.Require().NoError(err)
- s.True(gpk.verifySignature(msgHash, sig))
+ s.True(gpk.VerifySignature(msgHash, sig))
}
func TestDKGTSIGProtocol(t *testing.T) {