From 9c2f700be09c27e8a8d12fc5bc0ccd017d408a32 Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Wed, 26 Sep 2018 18:19:12 +0800 Subject: core: rename crypto/eth to crypto/ecdsa (#144) --- core/agreement-state_test.go | 10 +-- core/agreement_test.go | 6 +- core/authenticator_test.go | 4 +- core/compaction-chain_test.go | 8 +-- core/configuration-chain_test.go | 4 +- core/crypto/ecdsa/ecdsa.go | 130 +++++++++++++++++++++++++++++++++++++++ core/crypto/ecdsa/ecdsa_test.go | 93 ++++++++++++++++++++++++++++ core/crypto/eth/eth.go | 130 --------------------------------------- core/crypto/eth/eth_test.go | 93 ---------------------------- core/crypto_test.go | 12 ++-- core/dkg-tsig-protocol_test.go | 4 +- core/leader-selector_test.go | 12 ++-- core/shard_test.go | 4 +- core/test/blocks-generator.go | 4 +- core/test/governance.go | 4 +- 15 files changed, 259 insertions(+), 259 deletions(-) create mode 100644 core/crypto/ecdsa/ecdsa.go create mode 100644 core/crypto/ecdsa/ecdsa_test.go delete mode 100644 core/crypto/eth/eth.go delete mode 100644 core/crypto/eth/eth_test.go (limited to 'core') diff --git a/core/agreement-state_test.go b/core/agreement-state_test.go index 9c8c226..74ed7a0 100644 --- a/core/agreement-state_test.go +++ b/core/agreement-state_test.go @@ -25,7 +25,7 @@ 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/crypto/eth" + "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/types" ) @@ -85,7 +85,7 @@ func (s *AgreementStateTestSuite) prepareVote( } func (s *AgreementStateTestSuite) SetupTest() { - prvKey, err := eth.NewPrivateKey() + prvKey, err := ecdsa.NewPrivateKey() s.Require().Nil(err) s.ID = types.NewNodeID(prvKey.PublicKey()) s.prvKey = map[types.NodeID]crypto.PrivateKey{ @@ -105,7 +105,7 @@ func (s *AgreementStateTestSuite) newAgreement(numNode int) *agreement { notarySet := make(types.NodeIDs, numNode-1) for i := range notarySet { - prvKey, err := eth.NewPrivateKey() + prvKey, err := ecdsa.NewPrivateKey() s.Require().Nil(err) notarySet[i] = types.NewNodeID(prvKey.PublicKey()) s.prvKey[notarySet[i]] = prvKey @@ -156,7 +156,7 @@ func (s *AgreementStateTestSuite) TestPrepareState() { // is more than 2f+1, proposing the block v. a.data.period = 3 block := s.proposeBlock(a.data.leader) - prv, err := eth.NewPrivateKey() + prv, err := ecdsa.NewPrivateKey() s.Require().Nil(err) block.ProposerID = types.NewNodeID(prv.PublicKey()) s.Require().Nil(a.data.leader.prepareBlock(block, prv)) @@ -180,7 +180,7 @@ func (s *AgreementStateTestSuite) TestAckState() { blocks := make([]*types.Block, 3) for i := range blocks { blocks[i] = s.proposeBlock(a.data.leader) - prv, err := eth.NewPrivateKey() + prv, err := ecdsa.NewPrivateKey() s.Require().Nil(err) blocks[i].ProposerID = types.NewNodeID(prv.PublicKey()) s.Require().Nil(a.data.leader.prepareBlock(blocks[i], prv)) diff --git a/core/agreement_test.go b/core/agreement_test.go index 7780b94..2c98181 100644 --- a/core/agreement_test.go +++ b/core/agreement_test.go @@ -22,7 +22,7 @@ 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/crypto/eth" + "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/stretchr/testify/suite" ) @@ -67,7 +67,7 @@ type AgreementTestSuite struct { } func (s *AgreementTestSuite) SetupTest() { - prvKey, err := eth.NewPrivateKey() + prvKey, err := ecdsa.NewPrivateKey() s.Require().Nil(err) s.ID = types.NewNodeID(prvKey.PublicKey()) s.prvKey = map[types.NodeID]crypto.PrivateKey{ @@ -88,7 +88,7 @@ func (s *AgreementTestSuite) newAgreement(numNotarySet int) *agreement { notarySet := make(types.NodeIDs, numNotarySet-1) for i := range notarySet { - prvKey, err := eth.NewPrivateKey() + prvKey, err := ecdsa.NewPrivateKey() s.Require().Nil(err) notarySet[i] = types.NewNodeID(prvKey.PublicKey()) s.prvKey[notarySet[i]] = prvKey diff --git a/core/authenticator_test.go b/core/authenticator_test.go index 08a9179..b6c08d7 100644 --- a/core/authenticator_test.go +++ b/core/authenticator_test.go @@ -22,7 +22,7 @@ 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/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/stretchr/testify/suite" ) @@ -32,7 +32,7 @@ type AuthenticatorTestSuite struct { } func (s *AuthenticatorTestSuite) setupAuthenticator() *Authenticator { - k, err := eth.NewPrivateKey() + k, err := ecdsa.NewPrivateKey() s.NoError(err) return NewAuthenticator(k) } diff --git a/core/compaction-chain_test.go b/core/compaction-chain_test.go index 3664c81..6c8ec85 100644 --- a/core/compaction-chain_test.go +++ b/core/compaction-chain_test.go @@ -23,7 +23,7 @@ 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/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/stretchr/testify/suite" ) @@ -94,7 +94,7 @@ func (s *CompactionChainTestSuite) TestProcessBlock() { func (s *CompactionChainTestSuite) TestPrepareWitnessAck() { cc := s.newCompactionChain() blocks := s.generateBlocks(2, cc) - prv, err := eth.NewPrivateKey() + prv, err := ecdsa.NewPrivateKey() s.Require().Nil(err) block := blocks[1] @@ -113,9 +113,9 @@ func (s *CompactionChainTestSuite) TestPrepareWitnessAck() { func (s *CompactionChainTestSuite) TestProcessWitnessAck() { cc := s.newCompactionChain() blocks := s.generateBlocks(10, cc) - prv1, err := eth.NewPrivateKey() + prv1, err := ecdsa.NewPrivateKey() s.Require().Nil(err) - prv2, err := eth.NewPrivateKey() + prv2, err := ecdsa.NewPrivateKey() s.Require().Nil(err) nID1 := types.NewNodeID(prv1.PublicKey()) nID2 := types.NewNodeID(prv2.PublicKey()) diff --git a/core/configuration-chain_test.go b/core/configuration-chain_test.go index 4c1e62d..fa3e2df 100644 --- a/core/configuration-chain_test.go +++ b/core/configuration-chain_test.go @@ -27,7 +27,7 @@ import ( "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/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/test" "github.com/dexon-foundation/dexon-consensus-core/core/types" ) @@ -130,7 +130,7 @@ func (s *ConfigurationChainTestSuite) setupNodes(n int) { s.dkgIDs = make(map[types.NodeID]dkg.ID) ids := make(dkg.IDs, 0, n) for i := 0; i < n; i++ { - prvKey, err := eth.NewPrivateKey() + prvKey, err := ecdsa.NewPrivateKey() s.Require().NoError(err) nID := types.NewNodeID(prvKey.PublicKey()) s.nIDs = append(s.nIDs, nID) diff --git a/core/crypto/ecdsa/ecdsa.go b/core/crypto/ecdsa/ecdsa.go new file mode 100644 index 0000000..5f98395 --- /dev/null +++ b/core/crypto/ecdsa/ecdsa.go @@ -0,0 +1,130 @@ +// Copyright 2018 The dexon-consensus-core Authors +// This file is part of the dexon-consensus-core library. +// +// The dexon-consensus-core library is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation, either version 3 of the License, +// or (at your option) any later version. +// +// The dexon-consensus-core library is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser +// General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the dexon-consensus-core library. If not, see +// . + +package ecdsa + +import ( + "crypto/ecdsa" + + ethcrypto "github.com/dexon-foundation/dexon/crypto" + + "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/crypto" +) + +const cryptoType = "ecdsa" + +func init() { + crypto.RegisterSigToPub(cryptoType, SigToPub) +} + +// PrivateKey represents a private key structure used in geth and implments +// Crypto.PrivateKey interface. +type PrivateKey struct { + privateKey ecdsa.PrivateKey + publicKey publicKey +} + +// publicKey represents a public key structure used in geth and implements +// Crypto.PublicKey interface. +type publicKey struct { + publicKey []byte +} + +// NewPrivateKey creates a new PrivateKey structure. +func NewPrivateKey() (*PrivateKey, error) { + key, err := ethcrypto.GenerateKey() + if err != nil { + return nil, err + } + return &PrivateKey{ + privateKey: *key, + publicKey: *newPublicKey(key), + }, nil +} + +// newPublicKey creates a new PublicKey structure. +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) { + _, err := ethcrypto.DecompressPubkey(pubkey) + return publicKey{ + publicKey: pubkey, + }, err +} + +// PublicKey returns the public key associate this private key. +func (prv *PrivateKey) PublicKey() crypto.PublicKey { + return prv.publicKey +} + +// Sign calculates an ECDSA signature. +// +// This function is susceptible to chosen plaintext attacks that can leak +// information about the private key that is used for signing. Callers must +// be aware that the given hash cannot be chosen by an adversery. Common +// solution is to hash any input before calculating the signature. +// +// The produced signature is in the [R || S || V] format where V is 0 or 1. +func (prv *PrivateKey) Sign(hash common.Hash) ( + sig crypto.Signature, err error) { + s, err := ethcrypto.Sign(hash[:], &prv.privateKey) + sig = crypto.Signature{ + Type: cryptoType, + Signature: s, + } + return +} + +// VerifySignature checks that the given public key created signature over 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( + hash common.Hash, signature crypto.Signature) bool { + sig := signature.Signature + if len(sig) == 65 { + // The last byte is for ecrecover. + sig = sig[:64] + } + return ethcrypto.VerifySignature(pub.publicKey, hash[:], sig) +} + +// Compress encodes a public key to the 33-byte compressed format. +func (pub publicKey) Compress() []byte { + return pub.publicKey +} + +// Bytes returns the []byte representation of public key. +func (pub publicKey) Bytes() []byte { + return pub.Compress() +} + +// SigToPub returns the PublicKey that created the given signature. +func SigToPub( + hash common.Hash, signature crypto.Signature) (crypto.PublicKey, error) { + key, err := ethcrypto.SigToPub(hash[:], signature.Signature[:]) + if err != nil { + return publicKey{}, err + } + return publicKey{publicKey: ethcrypto.CompressPubkey(key)}, nil +} diff --git a/core/crypto/ecdsa/ecdsa_test.go b/core/crypto/ecdsa/ecdsa_test.go new file mode 100644 index 0000000..3543b04 --- /dev/null +++ b/core/crypto/ecdsa/ecdsa_test.go @@ -0,0 +1,93 @@ +// Copyright 2018 The dexon-consensus-core Authors +// This file is part of the dexon-consensus-core library. +// +// The dexon-consensus-core library is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation, either version 3 of the License, +// or (at your option) any later version. +// +// The dexon-consensus-core library is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser +// General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the dexon-consensus-core library. If not, see +// . + +package ecdsa + +import ( + "testing" + + "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/crypto" + "github.com/stretchr/testify/suite" +) + +type ETHCryptoTestSuite struct { + suite.Suite +} + +func (s *ETHCryptoTestSuite) TestSignature() { + prv1, err := NewPrivateKey() + s.Require().Nil(err) + hash1 := common.NewRandomHash() + hash2 := common.NewRandomHash() + + // Test that same private key should produce same signature. + sig11, err := prv1.Sign(hash1) + s.Require().Nil(err) + sig112, err := prv1.Sign(hash1) + s.Require().Nil(err) + s.Equal(sig11, sig112) + + // Test that different private key should produce different signature. + prv2, err := NewPrivateKey() + s.Require().Nil(err) + sig21, err := prv2.Sign(hash1) + s.Require().Nil(err) + s.NotEqual(sig11, sig21) + + // Test that different hash should produce different signature. + sig12, err := prv1.Sign(hash2) + s.Require().Nil(err) + s.NotEqual(sig11, sig12) + + // Test VerifySignature with correct public key. + pub1, ok := prv1.PublicKey().(publicKey) + s.Require().True(ok) + s.True(pub1.VerifySignature(hash1, sig11)) + + // Test VerifySignature with wrong hash. + s.False(pub1.VerifySignature(hash2, sig11)) + // Test VerifySignature with wrong signature. + s.False(pub1.VerifySignature(hash1, sig21)) + // Test VerifySignature with wrong public key. + pub2 := prv2.PublicKey() + s.False(pub2.VerifySignature(hash1, sig11)) + + // Test compress and decompress of public key. + compressPub1 := pub1.Compress() + decompressPub1, err := decompressPubkey(compressPub1) + s.Require().Nil(err) + s.Equal(pub1, decompressPub1) + s.True(decompressPub1.VerifySignature(hash1, sig11)) +} + +func (s *ETHCryptoTestSuite) TestSigToPub() { + prv, err := NewPrivateKey() + s.Require().Nil(err) + data := "DEXON is infinitely scalable and low-latency." + hash := crypto.Keccak256Hash([]byte(data)) + sigmsg, err := prv.Sign(hash) + s.Require().Nil(err) + + pubkey, err := SigToPub(hash, sigmsg) + s.Require().Nil(err) + s.Equal(pubkey, prv.PublicKey()) +} + +func TestCrypto(t *testing.T) { + suite.Run(t, new(ETHCryptoTestSuite)) +} diff --git a/core/crypto/eth/eth.go b/core/crypto/eth/eth.go deleted file mode 100644 index 41d05eb..0000000 --- a/core/crypto/eth/eth.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2018 The dexon-consensus-core Authors -// This file is part of the dexon-consensus-core library. -// -// The dexon-consensus-core library is free software: you can redistribute it -// and/or modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation, either version 3 of the License, -// or (at your option) any later version. -// -// The dexon-consensus-core library is distributed in the hope that it will be -// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser -// General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the dexon-consensus-core library. If not, see -// . - -package eth - -import ( - "crypto/ecdsa" - - ethcrypto "github.com/dexon-foundation/dexon/crypto" - - "github.com/dexon-foundation/dexon-consensus-core/common" - "github.com/dexon-foundation/dexon-consensus-core/core/crypto" -) - -const cryptoType = "eth" - -func init() { - crypto.RegisterSigToPub(cryptoType, SigToPub) -} - -// PrivateKey represents a private key structure used in geth and implments -// Crypto.PrivateKey interface. -type PrivateKey struct { - privateKey ecdsa.PrivateKey - publicKey publicKey -} - -// publicKey represents a public key structure used in geth and implements -// Crypto.PublicKey interface. -type publicKey struct { - publicKey []byte -} - -// NewPrivateKey creates a new PrivateKey structure. -func NewPrivateKey() (*PrivateKey, error) { - key, err := ethcrypto.GenerateKey() - if err != nil { - return nil, err - } - return &PrivateKey{ - privateKey: *key, - publicKey: *newPublicKey(key), - }, nil -} - -// newPublicKey creates a new PublicKey structure. -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) { - _, err := ethcrypto.DecompressPubkey(pubkey) - return publicKey{ - publicKey: pubkey, - }, err -} - -// PublicKey returns the public key associate this private key. -func (prv *PrivateKey) PublicKey() crypto.PublicKey { - return prv.publicKey -} - -// Sign calculates an ECDSA signature. -// -// This function is susceptible to chosen plaintext attacks that can leak -// information about the private key that is used for signing. Callers must -// be aware that the given hash cannot be chosen by an adversery. Common -// solution is to hash any input before calculating the signature. -// -// The produced signature is in the [R || S || V] format where V is 0 or 1. -func (prv *PrivateKey) Sign(hash common.Hash) ( - sig crypto.Signature, err error) { - s, err := ethcrypto.Sign(hash[:], &prv.privateKey) - sig = crypto.Signature{ - Type: cryptoType, - Signature: s, - } - return -} - -// VerifySignature checks that the given public key created signature over 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( - hash common.Hash, signature crypto.Signature) bool { - sig := signature.Signature - if len(sig) == 65 { - // The last byte is for ecrecover. - sig = sig[:64] - } - return ethcrypto.VerifySignature(pub.publicKey, hash[:], sig) -} - -// Compress encodes a public key to the 33-byte compressed format. -func (pub publicKey) Compress() []byte { - return pub.publicKey -} - -// Bytes returns the []byte representation of public key. -func (pub publicKey) Bytes() []byte { - return pub.Compress() -} - -// SigToPub returns the PublicKey that created the given signature. -func SigToPub( - hash common.Hash, signature crypto.Signature) (crypto.PublicKey, error) { - key, err := ethcrypto.SigToPub(hash[:], signature.Signature[:]) - if err != nil { - return publicKey{}, err - } - return publicKey{publicKey: ethcrypto.CompressPubkey(key)}, nil -} diff --git a/core/crypto/eth/eth_test.go b/core/crypto/eth/eth_test.go deleted file mode 100644 index acda1a8..0000000 --- a/core/crypto/eth/eth_test.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2018 The dexon-consensus-core Authors -// This file is part of the dexon-consensus-core library. -// -// The dexon-consensus-core library is free software: you can redistribute it -// and/or modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation, either version 3 of the License, -// or (at your option) any later version. -// -// The dexon-consensus-core library is distributed in the hope that it will be -// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser -// General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the dexon-consensus-core library. If not, see -// . - -package eth - -import ( - "testing" - - "github.com/dexon-foundation/dexon-consensus-core/common" - "github.com/dexon-foundation/dexon-consensus-core/core/crypto" - "github.com/stretchr/testify/suite" -) - -type ETHCryptoTestSuite struct { - suite.Suite -} - -func (s *ETHCryptoTestSuite) TestSignature() { - prv1, err := NewPrivateKey() - s.Require().Nil(err) - hash1 := common.NewRandomHash() - hash2 := common.NewRandomHash() - - // Test that same private key should produce same signature. - sig11, err := prv1.Sign(hash1) - s.Require().Nil(err) - sig112, err := prv1.Sign(hash1) - s.Require().Nil(err) - s.Equal(sig11, sig112) - - // Test that different private key should produce different signature. - prv2, err := NewPrivateKey() - s.Require().Nil(err) - sig21, err := prv2.Sign(hash1) - s.Require().Nil(err) - s.NotEqual(sig11, sig21) - - // Test that different hash should produce different signature. - sig12, err := prv1.Sign(hash2) - s.Require().Nil(err) - s.NotEqual(sig11, sig12) - - // Test VerifySignature with correct public key. - pub1, ok := prv1.PublicKey().(publicKey) - s.Require().True(ok) - s.True(pub1.VerifySignature(hash1, sig11)) - - // Test VerifySignature with wrong hash. - s.False(pub1.VerifySignature(hash2, sig11)) - // Test VerifySignature with wrong signature. - s.False(pub1.VerifySignature(hash1, sig21)) - // Test VerifySignature with wrong public key. - pub2 := prv2.PublicKey() - s.False(pub2.VerifySignature(hash1, sig11)) - - // Test compress and decompress of public key. - compressPub1 := pub1.Compress() - decompressPub1, err := decompressPubkey(compressPub1) - s.Require().Nil(err) - s.Equal(pub1, decompressPub1) - s.True(decompressPub1.VerifySignature(hash1, sig11)) -} - -func (s *ETHCryptoTestSuite) TestSigToPub() { - prv, err := NewPrivateKey() - s.Require().Nil(err) - data := "DEXON is infinitely scalable and low-latency." - hash := crypto.Keccak256Hash([]byte(data)) - sigmsg, err := prv.Sign(hash) - s.Require().Nil(err) - - pubkey, err := SigToPub(hash, sigmsg) - s.Require().Nil(err) - s.Equal(pubkey, prv.PublicKey()) -} - -func TestCrypto(t *testing.T) { - suite.Run(t, new(ETHCryptoTestSuite)) -} diff --git a/core/crypto_test.go b/core/crypto_test.go index 0d472cc..4c4955b 100644 --- a/core/crypto_test.go +++ b/core/crypto_test.go @@ -24,7 +24,7 @@ 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/crypto/dkg" - "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth" + "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/stretchr/testify/suite" ) @@ -99,7 +99,7 @@ func (s *CryptoTestSuite) generateCompactionChain( } func (s *CryptoTestSuite) TestWitnessAckSignature() { - prv, err := eth.NewPrivateKey() + prv, err := ecdsa.NewPrivateKey() pub := prv.PublicKey() s.Require().Nil(err) blocks, witnessAcks := s.generateCompactionChain(10, prv) @@ -150,7 +150,7 @@ func (s *CryptoTestSuite) generateBlockChain( } func (s *CryptoTestSuite) TestBlockSignature() { - prv, err := eth.NewPrivateKey() + prv, err := ecdsa.NewPrivateKey() pub := prv.PublicKey() s.Require().Nil(err) blocks := s.generateBlockChain(10, prv) @@ -178,7 +178,7 @@ func (s *CryptoTestSuite) TestBlockSignature() { } func (s *CryptoTestSuite) TestVoteSignature() { - prv, err := eth.NewPrivateKey() + prv, err := ecdsa.NewPrivateKey() s.Require().Nil(err) pub := prv.PublicKey() nID := types.NewNodeID(pub) @@ -197,7 +197,7 @@ func (s *CryptoTestSuite) TestVoteSignature() { func (s *CryptoTestSuite) TestCRSSignature() { crs := common.NewRandomHash() - prv, err := eth.NewPrivateKey() + prv, err := ecdsa.NewPrivateKey() s.Require().Nil(err) pub := prv.PublicKey() nID := types.NewNodeID(pub) @@ -212,7 +212,7 @@ func (s *CryptoTestSuite) TestCRSSignature() { } func (s *CryptoTestSuite) TestDKGSignature() { - prv, err := eth.NewPrivateKey() + prv, err := ecdsa.NewPrivateKey() s.Require().Nil(err) nID := types.NewNodeID(prv.PublicKey()) prvShare := &types.DKGPrivateShare{ diff --git a/core/dkg-tsig-protocol_test.go b/core/dkg-tsig-protocol_test.go index f7edcc2..967e07e 100644 --- a/core/dkg-tsig-protocol_test.go +++ b/core/dkg-tsig-protocol_test.go @@ -25,7 +25,7 @@ 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/crypto/dkg" - "github.com/dexon-foundation/dexon-consensus-core/core/crypto/eth" + "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/test" "github.com/dexon-foundation/dexon-consensus-core/core/types" ) @@ -96,7 +96,7 @@ func (s *DKGTSIGProtocolTestSuite) setupDKGParticipants(n int) { s.dkgIDs = make(map[types.NodeID]dkg.ID) ids := make(dkg.IDs, 0, n) for i := 0; i < n; i++ { - prvKey, err := eth.NewPrivateKey() + prvKey, err := ecdsa.NewPrivateKey() s.Require().NoError(err) nID := types.NewNodeID(prvKey.PublicKey()) s.nIDs = append(s.nIDs, nID) diff --git a/core/leader-selector_test.go b/core/leader-selector_test.go index 2bc1847..8da7e2a 100644 --- a/core/leader-selector_test.go +++ b/core/leader-selector_test.go @@ -23,7 +23,7 @@ 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/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/types" ) @@ -38,7 +38,7 @@ func (s *LeaderSelectorTestSuite) newLeader() *leaderSelector { func (s *LeaderSelectorTestSuite) TestDistance() { leader := s.newLeader() hash := common.NewRandomHash() - prv, err := eth.NewPrivateKey() + prv, err := ecdsa.NewPrivateKey() s.Require().Nil(err) sig, err := prv.Sign(hash) s.Require().Nil(err) @@ -48,9 +48,9 @@ func (s *LeaderSelectorTestSuite) TestDistance() { func (s *LeaderSelectorTestSuite) TestProbability() { leader := s.newLeader() - prv1, err := eth.NewPrivateKey() + prv1, err := ecdsa.NewPrivateKey() s.Require().Nil(err) - prv2, err := eth.NewPrivateKey() + prv2, err := ecdsa.NewPrivateKey() s.Require().Nil(err) for { hash := common.NewRandomHash() @@ -82,7 +82,7 @@ func (s *LeaderSelectorTestSuite) TestLeaderBlockHash() { leader := s.newLeader() blocks := make(map[common.Hash]*types.Block) for i := 0; i < 10; i++ { - prv, err := eth.NewPrivateKey() + prv, err := ecdsa.NewPrivateKey() s.Require().Nil(err) block := &types.Block{ ProposerID: types.NewNodeID(prv.PublicKey()), @@ -107,7 +107,7 @@ func (s *LeaderSelectorTestSuite) TestLeaderBlockHash() { func (s *LeaderSelectorTestSuite) TestPrepareBlock() { leader := s.newLeader() - prv, err := eth.NewPrivateKey() + prv, err := ecdsa.NewPrivateKey() s.Require().Nil(err) block := &types.Block{ ProposerID: types.NewNodeID(prv.PublicKey()), diff --git a/core/shard_test.go b/core/shard_test.go index 2a15f53..1b524ba 100644 --- a/core/shard_test.go +++ b/core/shard_test.go @@ -23,7 +23,7 @@ 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/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/test" "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/stretchr/testify/suite" @@ -92,7 +92,7 @@ type ShardTestSuite struct { func (s *ShardTestSuite) newTestShardMgr(cfg *types.Config) *testShardMgr { var req = s.Require() // Setup private key. - prvKey, err := eth.NewPrivateKey() + prvKey, err := ecdsa.NewPrivateKey() req.Nil(err) // Setup blockdb. db, err := blockdb.NewMemBackedBlockDB() diff --git a/core/test/blocks-generator.go b/core/test/blocks-generator.go index eacc436..904ee7a 100644 --- a/core/test/blocks-generator.go +++ b/core/test/blocks-generator.go @@ -26,7 +26,7 @@ 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/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/types" ) @@ -276,7 +276,7 @@ func (gen *BlocksGenerator) Generate( } nodePrvKeys = map[types.NodeID]crypto.PrivateKey{} for i := uint32(0); i < chainNum; i++ { - if prvKey, err = eth.NewPrivateKey(); err != nil { + if prvKey, err = ecdsa.NewPrivateKey(); err != nil { return } id := types.NewNodeID(prvKey.PublicKey()) diff --git a/core/test/governance.go b/core/test/governance.go index 81b71e5..7eca6f6 100644 --- a/core/test/governance.go +++ b/core/test/governance.go @@ -23,7 +23,7 @@ import ( "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/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/types" ) @@ -58,7 +58,7 @@ func NewGovernance(nodeCount int, lambda time.Duration) ( DKGMasterPublicKey: make(map[uint64][]*types.DKGMasterPublicKey), } for i := 0; i < nodeCount; i++ { - prv, err := eth.NewPrivateKey() + prv, err := ecdsa.NewPrivateKey() if err != nil { return nil, err } -- cgit v1.2.3