aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-09-26 16:55:15 +0800
committerGitHub <noreply@github.com>2018-09-26 16:55:15 +0800
commit663817d3e0d5a3c28cb0c5e378a533e242af5fdf (patch)
tree8d1952cc04a5735ce7cd060445667160bb21fc60
parente8468d7206dbee2a8dfb34bfccc29d0d7273a777 (diff)
downloaddexon-consensus-663817d3e0d5a3c28cb0c5e378a533e242af5fdf.tar.gz
dexon-consensus-663817d3e0d5a3c28cb0c5e378a533e242af5fdf.tar.zst
dexon-consensus-663817d3e0d5a3c28cb0c5e378a533e242af5fdf.zip
core: move crypto to core/crypto (#140)
- Move key-holder to authenticator Make core.keyHolder public as core.Authenticator, it is not required to make this part an interface. - Make private when there is no need to go public. - Fix data race
-rw-r--r--core/agreement-state_test.go4
-rw-r--r--core/agreement.go2
-rw-r--r--core/agreement_test.go4
-rw-r--r--core/authenticator.go (renamed from core/key-holder.go)52
-rw-r--r--core/authenticator_test.go (renamed from core/key-holder_test.go)24
-rw-r--r--core/compaction-chain.go2
-rw-r--r--core/compaction-chain_test.go2
-rw-r--r--core/configuration-chain.go2
-rw-r--r--core/configuration-chain_test.go13
-rw-r--r--core/consensus.go2
-rw-r--r--core/consensus_test.go2
-rw-r--r--core/crypto.go2
-rw-r--r--core/crypto/dkg/constant.go (renamed from crypto/dkg/constant.go)0
-rw-r--r--core/crypto/dkg/dkg.go (renamed from crypto/dkg/dkg.go)2
-rw-r--r--core/crypto/dkg/dkg_test.go (renamed from crypto/dkg/dkg_test.go)2
-rw-r--r--core/crypto/dkg/utils.go (renamed from crypto/dkg/utils.go)2
-rw-r--r--core/crypto/eth/eth.go (renamed from crypto/eth/eth.go)28
-rw-r--r--core/crypto/eth/eth_test.go (renamed from crypto/eth/eth_test.go)6
-rw-r--r--core/crypto/interfaces.go (renamed from crypto/interfaces.go)2
-rw-r--r--core/crypto/utils.go (renamed from crypto/utils.go)0
-rw-r--r--core/crypto/utils_test.go (renamed from crypto/utils_test.go)0
-rw-r--r--core/crypto_test.go6
-rw-r--r--core/dkg-tsig-protocol.go4
-rw-r--r--core/dkg-tsig-protocol_test.go6
-rw-r--r--core/interfaces.go36
-rw-r--r--core/leader-selector.go2
-rw-r--r--core/leader-selector_test.go2
-rw-r--r--core/shard.go2
-rw-r--r--core/shard_test.go2
-rw-r--r--core/test/blocks-generator.go4
-rw-r--r--core/test/governance.go4
-rw-r--r--core/types/block.go2
-rw-r--r--core/types/dkg.go4
-rw-r--r--core/types/node.go2
-rw-r--r--core/types/vote.go2
-rw-r--r--core/types/witness.go2
-rw-r--r--core/utils.go2
-rw-r--r--integration_test/node.go4
-rw-r--r--integration_test/utils.go2
-rw-r--r--simulation/governance.go2
-rw-r--r--simulation/node.go2
-rw-r--r--simulation/simulation.go2
42 files changed, 112 insertions, 135 deletions
diff --git a/core/agreement-state_test.go b/core/agreement-state_test.go
index 0142724..2aa50ac 100644
--- a/core/agreement-state_test.go
+++ b/core/agreement-state_test.go
@@ -24,9 +24,9 @@ import (
"github.com/stretchr/testify/suite"
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
)
type AgreementStateTestSuite struct {
diff --git a/core/agreement.go b/core/agreement.go
index ffc4ba8..1b1cbde 100644
--- a/core/agreement.go
+++ b/core/agreement.go
@@ -24,8 +24,8 @@ import (
"time"
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
)
// Errors for agreement module.
diff --git a/core/agreement_test.go b/core/agreement_test.go
index 681d7b6..4f8a3ac 100644
--- a/core/agreement_test.go
+++ b/core/agreement_test.go
@@ -21,9 +21,9 @@ import (
"testing"
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
"github.com/stretchr/testify/suite"
)
diff --git a/core/key-holder.go b/core/authenticator.go
index 355c823..480d6cc 100644
--- a/core/key-holder.go
+++ b/core/authenticator.go
@@ -19,55 +19,57 @@ package core
import (
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
)
-type keyHolder struct {
+// Authenticator verify data owner.
+type Authenticator struct {
prvKey crypto.PrivateKey
pubKey crypto.PublicKey
sigToPub SigToPubFn
}
-func newKeyHolder(prvKey crypto.PrivateKey, sigToPub SigToPubFn) *keyHolder {
- return &keyHolder{
+// NewAuthenticator constructs an Authenticator instance.
+func NewAuthenticator(prvKey crypto.PrivateKey, sigToPub SigToPubFn) *Authenticator {
+ return &Authenticator{
prvKey: prvKey,
pubKey: prvKey.PublicKey(),
sigToPub: sigToPub,
}
}
-// SignBlock implements core.Signer.
-func (h *keyHolder) SignBlock(b *types.Block) (err error) {
- b.ProposerID = types.NewNodeID(h.pubKey)
+// SignBlock signs a types.Block.
+func (au *Authenticator) SignBlock(b *types.Block) (err error) {
+ b.ProposerID = types.NewNodeID(au.pubKey)
if b.Hash, err = hashBlock(b); err != nil {
return
}
- if b.Signature, err = h.prvKey.Sign(b.Hash); err != nil {
+ if b.Signature, err = au.prvKey.Sign(b.Hash); err != nil {
return
}
return
}
-// SignVote implements core.Signer.
-func (h *keyHolder) SignVote(v *types.Vote) (err error) {
- v.ProposerID = types.NewNodeID(h.pubKey)
- v.Signature, err = h.prvKey.Sign(hashVote(v))
+// SignVote signs a types.Vote.
+func (au *Authenticator) SignVote(v *types.Vote) (err error) {
+ v.ProposerID = types.NewNodeID(au.pubKey)
+ v.Signature, err = au.prvKey.Sign(hashVote(v))
return
}
-// SignCRS implements core.Signer
-func (h *keyHolder) SignCRS(b *types.Block, crs common.Hash) (err error) {
- if b.ProposerID != types.NewNodeID(h.pubKey) {
+// SignCRS signs CRS signature of types.Block.
+func (au *Authenticator) SignCRS(b *types.Block, crs common.Hash) (err error) {
+ if b.ProposerID != types.NewNodeID(au.pubKey) {
err = ErrInvalidProposerID
return
}
- b.CRSSignature, err = h.prvKey.Sign(hashCRS(b, crs))
+ b.CRSSignature, err = au.prvKey.Sign(hashCRS(b, crs))
return
}
-// VerifyBlock implements core.CryptoVerifier.
-func (h *keyHolder) VerifyBlock(b *types.Block) (err error) {
+// VerifyBlock verifies the signature of types.Block.
+func (au *Authenticator) VerifyBlock(b *types.Block) (err error) {
hash, err := hashBlock(b)
if err != nil {
return
@@ -76,7 +78,7 @@ func (h *keyHolder) VerifyBlock(b *types.Block) (err error) {
err = ErrIncorrectHash
return
}
- pubKey, err := h.sigToPub(b.Hash, b.Signature)
+ pubKey, err := au.sigToPub(b.Hash, b.Signature)
if err != nil {
return
}
@@ -87,12 +89,12 @@ func (h *keyHolder) VerifyBlock(b *types.Block) (err error) {
return
}
-// VerifyVote implements core.CryptoVerifier.
-func (h *keyHolder) VerifyVote(v *types.Vote) (bool, error) {
- return verifyVoteSignature(v, h.sigToPub)
+// VerifyVote verifies the signature of types.Vote.
+func (au *Authenticator) VerifyVote(v *types.Vote) (bool, error) {
+ return verifyVoteSignature(v, au.sigToPub)
}
-// VerifyWitness implements core.CryptoVerifier.
-func (h *keyHolder) VerifyCRS(b *types.Block, crs common.Hash) (bool, error) {
- return verifyCRSSignature(b, crs, h.sigToPub)
+// VerifyCRS verifies the CRS signature of types.Block.
+func (au *Authenticator) VerifyCRS(b *types.Block, crs common.Hash) (bool, error) {
+ return verifyCRSSignature(b, crs, au.sigToPub)
}
diff --git a/core/key-holder_test.go b/core/authenticator_test.go
index cb5fda7..40b5e0c 100644
--- a/core/key-holder_test.go
+++ b/core/authenticator_test.go
@@ -22,23 +22,23 @@ import (
"time"
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
"github.com/stretchr/testify/suite"
)
-type KeyHolderTestSuite struct {
+type AuthenticatorTestSuite struct {
suite.Suite
}
-func (s *KeyHolderTestSuite) setupKeyHolder() *keyHolder {
+func (s *AuthenticatorTestSuite) setupAuthenticator() *Authenticator {
k, err := eth.NewPrivateKey()
s.NoError(err)
- return newKeyHolder(k, eth.SigToPub)
+ return NewAuthenticator(k, eth.SigToPub)
}
-func (s *KeyHolderTestSuite) TestBlock() {
- k := s.setupKeyHolder()
+func (s *AuthenticatorTestSuite) TestBlock() {
+ k := s.setupAuthenticator()
b := &types.Block{
ParentHash: common.NewRandomHash(),
Position: types.Position{
@@ -52,8 +52,8 @@ func (s *KeyHolderTestSuite) TestBlock() {
s.NoError(k.VerifyBlock(b))
}
-func (s *KeyHolderTestSuite) TestVote() {
- k := s.setupKeyHolder()
+func (s *AuthenticatorTestSuite) TestVote() {
+ k := s.setupAuthenticator()
v := &types.Vote{
ProposerID: types.NodeID{Hash: common.NewRandomHash()},
Type: types.VoteConfirm,
@@ -70,8 +70,8 @@ func (s *KeyHolderTestSuite) TestVote() {
s.NoError(err)
}
-func (s *KeyHolderTestSuite) TestCRS() {
- k := s.setupKeyHolder()
+func (s *AuthenticatorTestSuite) TestCRS() {
+ k := s.setupAuthenticator()
b := &types.Block{
ParentHash: common.NewRandomHash(),
Position: types.Position{
@@ -91,6 +91,6 @@ func (s *KeyHolderTestSuite) TestCRS() {
s.NoError(err)
}
-func TestKeyHolder(t *testing.T) {
- suite.Run(t, new(KeyHolderTestSuite))
+func TestAuthenticator(t *testing.T) {
+ suite.Run(t, new(AuthenticatorTestSuite))
}
diff --git a/core/compaction-chain.go b/core/compaction-chain.go
index 4405bbc..4bb3ffb 100644
--- a/core/compaction-chain.go
+++ b/core/compaction-chain.go
@@ -26,8 +26,8 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core/blockdb"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
)
// Errors for compaction chain.
diff --git a/core/compaction-chain_test.go b/core/compaction-chain_test.go
index 3603fb6..ed02b78 100644
--- a/core/compaction-chain_test.go
+++ b/core/compaction-chain_test.go
@@ -23,8 +23,8 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core/blockdb"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
"github.com/stretchr/testify/suite"
)
diff --git a/core/configuration-chain.go b/core/configuration-chain.go
index a6c0f39..46f02cc 100644
--- a/core/configuration-chain.go
+++ b/core/configuration-chain.go
@@ -23,8 +23,8 @@ import (
"sync"
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
)
// Errors for configuration chain..
diff --git a/core/configuration-chain_test.go b/core/configuration-chain_test.go
index ae82e42..fc3f48e 100644
--- a/core/configuration-chain_test.go
+++ b/core/configuration-chain_test.go
@@ -25,11 +25,11 @@ import (
"github.com/stretchr/testify/suite"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth"
"github.com/dexon-foundation/dexon-consensus-core/core/test"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/dkg"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
)
type ConfigurationChainTestSuite struct {
@@ -113,7 +113,12 @@ func (r *testCCReceiver) ProposeDKGAntiNackComplaint(
prv.Signature, err = prvKey.Sign(hashDKGPrivateShare(prv))
r.s.Require().NoError(err)
for _, cc := range r.nodes {
- err = cc.processPrivateShare(prv)
+ // Use Marshal/Unmarshal to do deep copy.
+ data, err := json.Marshal(prv)
+ r.s.Require().NoError(err)
+ prvCopy := &types.DKGPrivateShare{}
+ r.s.Require().NoError(json.Unmarshal(data, prvCopy))
+ err = cc.processPrivateShare(prvCopy)
r.s.Require().NoError(err)
}
}()
diff --git a/core/consensus.go b/core/consensus.go
index c7eea32..b8c8f77 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -27,8 +27,8 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core/blockdb"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
)
// SigToPubFn is a function to recover public key from signature.
diff --git a/core/consensus_test.go b/core/consensus_test.go
index a58d3e8..799698e 100644
--- a/core/consensus_test.go
+++ b/core/consensus_test.go
@@ -24,9 +24,9 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core/blockdb"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth"
"github.com/dexon-foundation/dexon-consensus-core/core/test"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
"github.com/stretchr/testify/suite"
)
diff --git a/core/crypto.go b/core/crypto.go
index 26e44f9..2a1e3c5 100644
--- a/core/crypto.go
+++ b/core/crypto.go
@@ -21,8 +21,8 @@ import (
"encoding/binary"
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
)
func hashWitness(block *types.Block) (common.Hash, error) {
diff --git a/crypto/dkg/constant.go b/core/crypto/dkg/constant.go
index 119613b..119613b 100644
--- a/crypto/dkg/constant.go
+++ b/core/crypto/dkg/constant.go
diff --git a/crypto/dkg/dkg.go b/core/crypto/dkg/dkg.go
index f2a2f3a..fe05e96 100644
--- a/crypto/dkg/dkg.go
+++ b/core/crypto/dkg/dkg.go
@@ -24,7 +24,7 @@ import (
"github.com/Spiderpowa/bls/ffi/go/bls"
"github.com/dexon-foundation/dexon-consensus-core/common"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
)
var (
diff --git a/crypto/dkg/dkg_test.go b/core/crypto/dkg/dkg_test.go
index badb0ce..9488dcc 100644
--- a/crypto/dkg/dkg_test.go
+++ b/core/crypto/dkg/dkg_test.go
@@ -27,7 +27,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/dexon-foundation/dexon-consensus-core/common"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
)
type DKGTestSuite struct {
diff --git a/crypto/dkg/utils.go b/core/crypto/dkg/utils.go
index 3684964..967973d 100644
--- a/crypto/dkg/utils.go
+++ b/core/crypto/dkg/utils.go
@@ -22,7 +22,7 @@ import (
"github.com/Spiderpowa/bls/ffi/go/bls"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
)
// PartialSignature is a partial signature in DKG+TSIG protocol.
diff --git a/crypto/eth/eth.go b/core/crypto/eth/eth.go
index c3c5a7c..e82ac29 100644
--- a/crypto/eth/eth.go
+++ b/core/crypto/eth/eth.go
@@ -23,19 +23,19 @@ import (
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/dexon-foundation/dexon-consensus-core/common"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
)
// PrivateKey represents a private key structure used in geth and implments
// Crypto.PrivateKey interface.
type PrivateKey struct {
privateKey ecdsa.PrivateKey
- publicKey PublicKey
+ publicKey publicKey
}
-// PublicKey represents a public key structure used in geth and implements
+// publicKey represents a public key structure used in geth and implements
// Crypto.PublicKey interface.
-type PublicKey struct {
+type publicKey struct {
publicKey []byte
}
@@ -52,16 +52,16 @@ func NewPrivateKey() (*PrivateKey, error) {
}
// newPublicKey creates a new PublicKey structure.
-func newPublicKey(prvKey *ecdsa.PrivateKey) *PublicKey {
- return &PublicKey{
+func newPublicKey(prvKey *ecdsa.PrivateKey) *publicKey {
+ return &publicKey{
publicKey: ethcrypto.CompressPubkey(&prvKey.PublicKey),
}
}
-// DecompressPubkey parses a public key in the 33-byte compressed format.
-func DecompressPubkey(pubkey []byte) (PublicKey, error) {
+// decompressPubkey parses a public key in the 33-byte compressed format.
+func decompressPubkey(pubkey []byte) (publicKey, error) {
_, err := ethcrypto.DecompressPubkey(pubkey)
- return PublicKey{
+ return publicKey{
publicKey: pubkey,
}, err
}
@@ -90,7 +90,7 @@ func (prv *PrivateKey) Sign(hash common.Hash) (
// The public key should be in compressed (33 bytes) or uncompressed (65 bytes)
// format.
// The signature should have the 64 byte [R || S] format.
-func (pub PublicKey) VerifySignature(
+func (pub publicKey) VerifySignature(
hash common.Hash, signature crypto.Signature) bool {
if len(signature) == 65 {
// The last byte is for ecrecover.
@@ -100,12 +100,12 @@ func (pub PublicKey) VerifySignature(
}
// Compress encodes a public key to the 33-byte compressed format.
-func (pub PublicKey) Compress() []byte {
+func (pub publicKey) Compress() []byte {
return pub.publicKey
}
// Bytes returns the []byte representation of public key.
-func (pub PublicKey) Bytes() []byte {
+func (pub publicKey) Bytes() []byte {
return pub.Compress()
}
@@ -114,7 +114,7 @@ func SigToPub(
hash common.Hash, signature crypto.Signature) (crypto.PublicKey, error) {
key, err := ethcrypto.SigToPub(hash[:], signature[:])
if err != nil {
- return PublicKey{}, err
+ return publicKey{}, err
}
- return PublicKey{publicKey: ethcrypto.CompressPubkey(key)}, nil
+ return publicKey{publicKey: ethcrypto.CompressPubkey(key)}, nil
}
diff --git a/crypto/eth/eth_test.go b/core/crypto/eth/eth_test.go
index f6f48cb..acda1a8 100644
--- a/crypto/eth/eth_test.go
+++ b/core/crypto/eth/eth_test.go
@@ -21,7 +21,7 @@ import (
"testing"
"github.com/dexon-foundation/dexon-consensus-core/common"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
"github.com/stretchr/testify/suite"
)
@@ -55,7 +55,7 @@ func (s *ETHCryptoTestSuite) TestSignature() {
s.NotEqual(sig11, sig12)
// Test VerifySignature with correct public key.
- pub1, ok := prv1.PublicKey().(PublicKey)
+ pub1, ok := prv1.PublicKey().(publicKey)
s.Require().True(ok)
s.True(pub1.VerifySignature(hash1, sig11))
@@ -69,7 +69,7 @@ func (s *ETHCryptoTestSuite) TestSignature() {
// Test compress and decompress of public key.
compressPub1 := pub1.Compress()
- decompressPub1, err := DecompressPubkey(compressPub1)
+ decompressPub1, err := decompressPubkey(compressPub1)
s.Require().Nil(err)
s.Equal(pub1, decompressPub1)
s.True(decompressPub1.VerifySignature(hash1, sig11))
diff --git a/crypto/interfaces.go b/core/crypto/interfaces.go
index 280082e..ac2754d 100644
--- a/crypto/interfaces.go
+++ b/core/crypto/interfaces.go
@@ -31,7 +31,7 @@ type PrivateKey interface {
PublicKey() PublicKey
// Sign calculates a signature.
- Sign(hash common.Hash) (sig Signature, err error)
+ Sign(hash common.Hash) (Signature, error)
}
// PublicKey describes the asymmetric cryptography interface that interacts
diff --git a/crypto/utils.go b/core/crypto/utils.go
index 07a8b2b..07a8b2b 100644
--- a/crypto/utils.go
+++ b/core/crypto/utils.go
diff --git a/crypto/utils_test.go b/core/crypto/utils_test.go
index 977027a..977027a 100644
--- a/crypto/utils_test.go
+++ b/core/crypto/utils_test.go
diff --git a/core/crypto_test.go b/core/crypto_test.go
index 6c807da..4ff4606 100644
--- a/core/crypto_test.go
+++ b/core/crypto_test.go
@@ -22,10 +22,10 @@ import (
"time"
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/dkg"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
"github.com/stretchr/testify/suite"
)
diff --git a/core/dkg-tsig-protocol.go b/core/dkg-tsig-protocol.go
index 0f5cb0b..a69cdd2 100644
--- a/core/dkg-tsig-protocol.go
+++ b/core/dkg-tsig-protocol.go
@@ -21,9 +21,9 @@ import (
"fmt"
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/dkg"
)
// Errors for dkg module.
diff --git a/core/dkg-tsig-protocol_test.go b/core/dkg-tsig-protocol_test.go
index 0c938f7..97d9d34 100644
--- a/core/dkg-tsig-protocol_test.go
+++ b/core/dkg-tsig-protocol_test.go
@@ -23,11 +23,11 @@ import (
"github.com/stretchr/testify/suite"
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth"
"github.com/dexon-foundation/dexon-consensus-core/core/test"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/dkg"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
)
type DKGTSIGProtocolTestSuite struct {
diff --git a/core/interfaces.go b/core/interfaces.go
index 7f6ff2b..eebf8ff 100644
--- a/core/interfaces.go
+++ b/core/interfaces.go
@@ -21,8 +21,8 @@ import (
"time"
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
)
// Application describes the application interface that interacts with DEXON
@@ -56,7 +56,7 @@ type Debug interface {
// TotalOrderingDelivered is called when the total ordering algorithm deliver
// a set of block.
- TotalOrderingDelivered(blockHashes common.Hashes, early bool)
+ TotalOrderingDelivered(common.Hashes, bool)
}
// Network describs the network interface that interacts with DEXON consensus
@@ -101,7 +101,7 @@ type Governance interface {
ProposeThresholdSignature(round uint64, signature crypto.Signature)
// Get a ThresholdSignature of round.
- GetThresholdSignature(round uint64) (sig crypto.Signature, exist bool)
+ GetThresholdSignature(round uint64) (crypto.Signature, bool)
//// DKG-related methods.
@@ -126,33 +126,3 @@ type Ticker interface {
// Stop the ticker.
Stop()
}
-
-// Signer defines a role to sign data.
-type Signer interface {
- // SignBlock signs a block.
- SignBlock(b *types.Block) error
-
- // SignVote signs a vote.
- SignVote(v *types.Vote) error
-
- // SignCRS sign a block's CRS signature.
- SignCRS(b *types.Block, crs common.Hash) error
-}
-
-// CryptoVerifier defines a role to verify data in crypto's way.
-type CryptoVerifier interface {
- // VerifyBlock verifies if a block is properly signed or not.
- VerifyBlock(b *types.Block) (ok bool, err error)
-
- // VerifyVote verfies if a vote is properly signed or not.
- VerifyVote(v *types.Vote) (ok bool, err error)
-
- // VerifyCRS verifies if a CRS signature of one block is valid or not.
- VerifyCRS(b *types.Block, crs common.Hash) (ok bool, err error)
-}
-
-// Authenticator verify/sign who own the data.
-type Authenticator interface {
- Signer
- CryptoVerifier
-}
diff --git a/core/leader-selector.go b/core/leader-selector.go
index ce5134a..8a20055 100644
--- a/core/leader-selector.go
+++ b/core/leader-selector.go
@@ -22,8 +22,8 @@ import (
"math/big"
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
)
// Errors for leader module.
diff --git a/core/leader-selector_test.go b/core/leader-selector_test.go
index 211680d..02562ba 100644
--- a/core/leader-selector_test.go
+++ b/core/leader-selector_test.go
@@ -23,8 +23,8 @@ import (
"github.com/stretchr/testify/suite"
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
)
type LeaderSelectorTestSuite struct {
diff --git a/core/shard.go b/core/shard.go
index 270b070..28b64f1 100644
--- a/core/shard.go
+++ b/core/shard.go
@@ -23,8 +23,8 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core/blockdb"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
)
// Shard represents a unit to produce a global ordering from multiple chains.
diff --git a/core/shard_test.go b/core/shard_test.go
index 42c8d7b..2a9016b 100644
--- a/core/shard_test.go
+++ b/core/shard_test.go
@@ -23,9 +23,9 @@ import (
"time"
"github.com/dexon-foundation/dexon-consensus-core/core/blockdb"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth"
"github.com/dexon-foundation/dexon-consensus-core/core/test"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
"github.com/stretchr/testify/suite"
)
diff --git a/core/test/blocks-generator.go b/core/test/blocks-generator.go
index 4038450..eacc436 100644
--- a/core/test/blocks-generator.go
+++ b/core/test/blocks-generator.go
@@ -25,9 +25,9 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core/blockdb"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
)
// TODO(mission): blocks generator should generate blocks based on chain,
diff --git a/core/test/governance.go b/core/test/governance.go
index 137662f..81b71e5 100644
--- a/core/test/governance.go
+++ b/core/test/governance.go
@@ -22,9 +22,9 @@ import (
"sync"
"time"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
)
var (
diff --git a/core/types/block.go b/core/types/block.go
index ddd0abd..e4b4466 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -27,7 +27,7 @@ import (
"time"
"github.com/dexon-foundation/dexon-consensus-core/common"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
)
var (
diff --git a/core/types/dkg.go b/core/types/dkg.go
index a21c983..16737c6 100644
--- a/core/types/dkg.go
+++ b/core/types/dkg.go
@@ -20,8 +20,8 @@ package types
import (
"fmt"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/dkg"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg"
)
// DKGPrivateShare describe a secret share in DKG protocol.
diff --git a/core/types/node.go b/core/types/node.go
index 8a856de..177e407 100644
--- a/core/types/node.go
+++ b/core/types/node.go
@@ -21,7 +21,7 @@ import (
"bytes"
"github.com/dexon-foundation/dexon-consensus-core/common"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
)
// NodeID is the ID type for nodes.
diff --git a/core/types/vote.go b/core/types/vote.go
index e92aa67..294bc74 100644
--- a/core/types/vote.go
+++ b/core/types/vote.go
@@ -21,7 +21,7 @@ import (
"fmt"
"github.com/dexon-foundation/dexon-consensus-core/common"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
)
// VoteType is the type of vote.
diff --git a/core/types/witness.go b/core/types/witness.go
index 46aa1cc..3c455d8 100644
--- a/core/types/witness.go
+++ b/core/types/witness.go
@@ -23,7 +23,7 @@ import (
"time"
"github.com/dexon-foundation/dexon-consensus-core/common"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
)
// WitnessAck represents the acking to the compaction chain.
diff --git a/core/utils.go b/core/utils.go
index 30456ef..3c1d211 100644
--- a/core/utils.go
+++ b/core/utils.go
@@ -25,8 +25,8 @@ import (
"time"
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
)
var (
diff --git a/integration_test/node.go b/integration_test/node.go
index 118a38f..4fdd746 100644
--- a/integration_test/node.go
+++ b/integration_test/node.go
@@ -26,10 +26,10 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core"
"github.com/dexon-foundation/dexon-consensus-core/core/blockdb"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth"
"github.com/dexon-foundation/dexon-consensus-core/core/test"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
)
type consensusEventType int
diff --git a/integration_test/utils.go b/integration_test/utils.go
index 6a94a17..5b414c5 100644
--- a/integration_test/utils.go
+++ b/integration_test/utils.go
@@ -4,9 +4,9 @@ import (
"time"
"github.com/dexon-foundation/dexon-consensus-core/core/blockdb"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/core/test"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
)
// PrepareNodes setups nodes for testing.
diff --git a/simulation/governance.go b/simulation/governance.go
index 133276c..a48e221 100644
--- a/simulation/governance.go
+++ b/simulation/governance.go
@@ -22,8 +22,8 @@ import (
"sync"
"time"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/simulation/config"
)
diff --git a/simulation/node.go b/simulation/node.go
index 8b282c7..2d5c7a4 100644
--- a/simulation/node.go
+++ b/simulation/node.go
@@ -24,8 +24,8 @@ import (
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core"
"github.com/dexon-foundation/dexon-consensus-core/core/blockdb"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
- "github.com/dexon-foundation/dexon-consensus-core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/simulation/config"
)
diff --git a/simulation/simulation.go b/simulation/simulation.go
index 61e09c7..c14c953 100644
--- a/simulation/simulation.go
+++ b/simulation/simulation.go
@@ -20,7 +20,7 @@ package simulation
import (
"sync"
- "github.com/dexon-foundation/dexon-consensus-core/crypto/eth"
+ "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth"
"github.com/dexon-foundation/dexon-consensus-core/simulation/config"
)