diff --git a/pkg/consensus/block.go b/pkg/consensus/block.go index cabb0c684..87a4fae35 100644 --- a/pkg/consensus/block.go +++ b/pkg/consensus/block.go @@ -24,8 +24,8 @@ var _ dbft.Block[util.Uint256] = (*neoBlock)(nil) // Sign implements the block.Block interface. func (n *neoBlock) Sign(key dbft.PrivateKey) error { - k := key.(*privateKey) - sig := k.PrivateKey.SignHashable(uint32(n.network), &n.Block) + k := key.(*keys.PrivateKey) + sig := k.SignHashable(uint32(n.network), &n.Block) n.signature = sig return nil } diff --git a/pkg/consensus/block_test.go b/pkg/consensus/block_test.go index 67a9e2488..1bfeb6cef 100644 --- a/pkg/consensus/block_test.go +++ b/pkg/consensus/block_test.go @@ -15,7 +15,7 @@ func TestNeoBlock_Sign(t *testing.T) { b := new(neoBlock) priv, _ := keys.NewPrivateKey() - require.NoError(t, b.Sign(&privateKey{PrivateKey: priv})) + require.NoError(t, b.Sign(priv)) require.NoError(t, b.Verify(priv.PublicKey(), b.Signature())) } diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index d4763d157..5f251c8ed 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -449,7 +449,7 @@ func (s *service) getKeyPair(pubs []dbft.PublicKey) (int, dbft.PrivateKey, dbft. } } - return i, &privateKey{PrivateKey: acc.PrivateKey()}, acc.PublicKey() + return i, acc.PrivateKey(), acc.PublicKey() } } return -1, nil, nil @@ -495,7 +495,7 @@ func (s *service) OnTransaction(tx *transaction.Transaction) { } func (s *service) broadcast(p dbft.ConsensusPayload[util.Uint256]) { - if err := p.(*Payload).Sign(s.dbft.Priv.(*privateKey)); err != nil { + if err := p.(*Payload).Sign(s.dbft.Priv.(*keys.PrivateKey)); err != nil { s.log.Warn("can't sign consensus payload", zap.Error(err)) } diff --git a/pkg/consensus/consensus_test.go b/pkg/consensus/consensus_test.go index 3ec43501a..c7066aaca 100644 --- a/pkg/consensus/consensus_test.go +++ b/pkg/consensus/consensus_test.go @@ -532,9 +532,9 @@ func (bq testBlockQueuer) PutBlock(b *coreb.Block) error { return bq.bc.AddBlock(b) } -func getTestValidator(i int) (*privateKey, *keys.PublicKey) { +func getTestValidator(i int) (*keys.PrivateKey, *keys.PublicKey) { key := testchain.PrivateKey(i) - return &privateKey{PrivateKey: key}, key.PublicKey() + return key, key.PublicKey() } func newSingleTestChain(t *testing.T) *core.Blockchain { diff --git a/pkg/consensus/crypto.go b/pkg/consensus/crypto.go deleted file mode 100644 index 647282426..000000000 --- a/pkg/consensus/crypto.go +++ /dev/null @@ -1,19 +0,0 @@ -package consensus - -import ( - "github.com/nspcc-dev/dbft" - "github.com/nspcc-dev/neo-go/pkg/crypto/keys" -) - -// privateKey is a wrapper around keys.PrivateKey -// which implements the crypto.PrivateKey interface. -type privateKey struct { - *keys.PrivateKey -} - -var _ dbft.PrivateKey = &privateKey{} - -// Sign implements the dbft's crypto.PrivateKey interface. -func (p *privateKey) Sign(data []byte) ([]byte, error) { - return p.PrivateKey.Sign(data), nil -} diff --git a/pkg/consensus/crypto_test.go b/pkg/consensus/crypto_test.go index 8ba0b9c95..bbcb6b728 100644 --- a/pkg/consensus/crypto_test.go +++ b/pkg/consensus/crypto_test.go @@ -9,18 +9,15 @@ import ( ) func TestCrypt(t *testing.T) { - key, err := keys.NewPrivateKey() + priv, err := keys.NewPrivateKey() require.NoError(t, err) - priv := privateKey{key} - - pub := key.PublicKey() + pub := priv.PublicKey() data := []byte{1, 2, 3, 4} hash := sha256.Sum256(data) - sign, err := priv.Sign(data) - require.NoError(t, err) + sign := priv.Sign(data) require.True(t, pub.Verify(sign, hash[:])) sign[0] = ^sign[0] diff --git a/pkg/consensus/payload.go b/pkg/consensus/payload.go index 4f2ba0671..8c0784fcd 100644 --- a/pkg/consensus/payload.go +++ b/pkg/consensus/payload.go @@ -5,6 +5,7 @@ import ( "github.com/nspcc-dev/dbft" "github.com/nspcc-dev/neo-go/pkg/config/netmode" + "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/io" npayload "github.com/nspcc-dev/neo-go/pkg/network/payload" "github.com/nspcc-dev/neo-go/pkg/util" @@ -119,9 +120,9 @@ func (p *Payload) EncodeBinary(w *io.BinWriter) { // Sign signs payload using the private key. // It also sets corresponding verification and invocation scripts. -func (p *Payload) Sign(key *privateKey) error { +func (p *Payload) Sign(key *keys.PrivateKey) error { p.encodeData() - sig := key.PrivateKey.SignHashable(uint32(p.network), &p.Extensible) + sig := key.SignHashable(uint32(p.network), &p.Extensible) buf := io.NewBufBinWriter() emit.Bytes(buf.BinWriter, sig) diff --git a/pkg/consensus/payload_test.go b/pkg/consensus/payload_test.go index cf6e761ff..e4c34c68d 100644 --- a/pkg/consensus/payload_test.go +++ b/pkg/consensus/payload_test.go @@ -249,11 +249,9 @@ func randomRecoveryMessage(t *testing.T) *recoveryMessage { } func TestPayload_Sign(t *testing.T) { - key, err := keys.NewPrivateKey() + priv, err := keys.NewPrivateKey() require.NoError(t, err) - priv := &privateKey{key} - p := randomPayload(t, prepareRequestType) h := priv.PublicKey().GetScriptHash() bc := newTestChain(t, false) diff --git a/pkg/consensus/recovery_message_test.go b/pkg/consensus/recovery_message_test.go index 58a1ac22a..2c7737c7c 100644 --- a/pkg/consensus/recovery_message_test.go +++ b/pkg/consensus/recovery_message_test.go @@ -6,6 +6,7 @@ import ( "github.com/nspcc-dev/dbft" "github.com/nspcc-dev/neo-go/internal/testchain" "github.com/nspcc-dev/neo-go/pkg/config/netmode" + "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/require" ) @@ -21,7 +22,7 @@ func TestRecoveryMessageSetters(t *testing.T) { func testRecoveryMessageSetters(t *testing.T, enableStateRoot bool) { srv := newTestServiceWithState(t, enableStateRoot) - privs := make([]*privateKey, testchain.Size()) + privs := make([]*keys.PrivateKey, testchain.Size()) pubs := make([]dbft.PublicKey, testchain.Size()) for i := range testchain.Size() { privs[i], pubs[i] = getTestValidator(i)