diff --git a/abci/example/kvstore/verify.go b/abci/example/kvstore/verify.go index 6cc4de96d6..01826a4cee 100644 --- a/abci/example/kvstore/verify.go +++ b/abci/example/kvstore/verify.go @@ -7,6 +7,7 @@ import ( "github.com/dashpay/dashd-go/btcjson" abci "github.com/dashpay/tenderdash/abci/types" + "github.com/dashpay/tenderdash/crypto" "github.com/dashpay/tenderdash/crypto/encoding" tmbytes "github.com/dashpay/tenderdash/libs/bytes" types1 "github.com/dashpay/tenderdash/proto/tendermint/types" @@ -50,7 +51,7 @@ func makeBlockSignItem( req *abci.RequestFinalizeBlock, quorumType btcjson.LLMQType, quorumHash []byte, -) types.SignItem { +) crypto.SignItem { reqID := types.BlockRequestID(req.Height, req.Round) cv, err := req.ToCanonicalVote() if err != nil { @@ -60,19 +61,19 @@ func makeBlockSignItem( if err != nil { panic(fmt.Errorf("block sign item: %w", err)) } - return types.NewSignItem(quorumType, quorumHash, reqID, raw) + return crypto.NewSignItem(quorumType, quorumHash, reqID, raw) } func makeVoteExtensionSignItems( req *abci.RequestFinalizeBlock, quorumType btcjson.LLMQType, quorumHash []byte, -) map[types1.VoteExtensionType][]types.SignItem { - items := make(map[types1.VoteExtensionType][]types.SignItem) +) map[types1.VoteExtensionType][]crypto.SignItem { + items := make(map[types1.VoteExtensionType][]crypto.SignItem) protoExtensionsMap := types1.VoteExtensionsToMap(req.Commit.ThresholdVoteExtensions) for t, exts := range protoExtensionsMap { if items[t] == nil && len(exts) > 0 { - items[t] = make([]types.SignItem, len(exts)) + items[t] = make([]crypto.SignItem, len(exts)) } chainID := req.Block.Header.ChainID for i, ext := range exts { @@ -82,7 +83,7 @@ func makeVoteExtensionSignItems( panic(fmt.Errorf("vote extension sign items: %w", err)) } - items[t][i] = types.NewSignItem(quorumType, quorumHash, reqID, raw) + items[t][i] = crypto.NewSignItem(quorumType, quorumHash, reqID, raw) } } return items diff --git a/crypto/quorum.go b/crypto/quorum.go index 70b0753611..c9dafd57fb 100644 --- a/crypto/quorum.go +++ b/crypto/quorum.go @@ -1,15 +1,106 @@ package crypto import ( + "bytes" + "fmt" + bls "github.com/dashpay/bls-signatures/go-bindings" "github.com/dashpay/dashd-go/btcjson" + "github.com/rs/zerolog" ) -// SignID returns signing session data that will be signed to get threshold signature share. +// SignItem represents signing session data (in field SignItem.ID) that will be signed to get threshold signature share. // See DIP-0007 -func SignID(llmqType btcjson.LLMQType, quorumHash QuorumHash, requestID []byte, messageHash []byte) []byte { +type SignItem struct { + ReqID []byte // Request ID for quorum signing + ID []byte // Signature ID + Raw []byte // Raw data to be signed + Hash []byte // Checksum of Raw + QuorumType btcjson.LLMQType // Quorum type for which this sign item is created + QuorumHash []byte // Quorum hash for which this sign item is created +} + +// Validate validates prepared data for signing +func (i *SignItem) Validate() error { + if len(i.ReqID) != DefaultHashSize { + return fmt.Errorf("invalid request ID size: %X", i.ReqID) + } + if len(i.Hash) != DefaultHashSize { + return fmt.Errorf("invalid hash size: %X", i.ReqID) + } + if len(i.QuorumHash) != DefaultHashSize { + return fmt.Errorf("invalid quorum hash size: %X", i.ReqID) + } + if len(i.Raw) > 0 { + if !bytes.Equal(Checksum(i.Raw), i.Hash) { + return fmt.Errorf("invalid hash %X for raw data: %X", i.Hash, i.Raw) + } + } + return nil +} + +func (i SignItem) MarshalZerologObject(e *zerolog.Event) { + e.Hex("signBytes", i.Raw) + e.Hex("signRequestID", i.ReqID) + e.Hex("signID", i.ID) + e.Hex("signHash", i.Hash) +} + +// NewSignItem creates a new instance of SignItem with calculating a hash for a raw and creating signID +// +// Arguments: +// - quorumType: quorum type +// - quorumHash: quorum hash +// - reqID: sign request ID +// - raw: raw data to be signed; it will be hashed with crypto.Checksum() +func NewSignItem(quorumType btcjson.LLMQType, quorumHash, reqID, raw []byte) SignItem { + msgHash := Checksum(raw) + item := NewSignItemFromHash(quorumType, quorumHash, reqID, msgHash) + item.Raw = raw + + return item +} + +// Create a new sign item without raw value, using provided hash. +func NewSignItemFromHash(quorumType btcjson.LLMQType, quorumHash, reqID, msgHash []byte) SignItem { + item := SignItem{ + ReqID: reqID, + Hash: msgHash, + QuorumType: quorumType, + QuorumHash: quorumHash, + Raw: nil, // Raw is empty, as we don't have it + } + item.UpdateID() + + return item +} + +func (i *SignItem) UpdateID() { + if err := i.Validate(); err != nil { + panic("invalid sign item: " + err.Error()) + } + // FIXME: previously we had reversals, but this doesn't work with Core test vectors + // So + // quorumHash := tmbytes.Reverse(i.QuorumHash) + quorumHash := i.QuorumHash + // requestID := tmbytes.Reverse(i.ReqID) + requestID := i.ReqID + // messageHash := tmbytes.Reverse(i.Hash) + messageHash := i.Hash + + llmqType := i.QuorumType + + // if testing.Testing() { + // fmt.Printf("generating sign ID using bls.BuildSignHash for %d %X %X %X\n", llmqType, quorumHash, requestID, messageHash) + // out := append([]byte{byte(llmqType)}, quorumHash...) + // out = append(out, requestID...) + // out = append(out, messageHash...) + + // fmt.Printf("data before sha256: %X\n", out) + // fmt.Printf("sha256(sha256(data)): %X\n", crypto.Checksum((crypto.Checksum(out)))) + // } var blsQuorumHash bls.Hash - copy(blsQuorumHash[:], quorumHash.Bytes()) + copy(blsQuorumHash[:], quorumHash) var blsRequestID bls.Hash copy(blsRequestID[:], requestID) @@ -22,5 +113,5 @@ func SignID(llmqType btcjson.LLMQType, quorumHash QuorumHash, requestID []byte, signHash := make([]byte, 32) copy(signHash, blsSignHash[:]) - return signHash + i.ID = signHash } diff --git a/dash/core/mock.go b/dash/core/mock.go index e396f646a7..4d9f07eb80 100644 --- a/dash/core/mock.go +++ b/dash/core/mock.go @@ -152,13 +152,8 @@ func (mc *MockClient) QuorumSign( if !mc.canSign { return nil, errors.New("dash core mock client not set up for signing") } + signID := crypto.NewSignItemFromHash(quorumType, quorumHash, requestID, messageHash).ID - signID := crypto.SignID( - quorumType, - tmbytes.Reverse(quorumHash), - tmbytes.Reverse(requestID), - tmbytes.Reverse(messageHash), - ) privateKey, err := mc.localPV.GetPrivateKey(context.Background(), quorumHash) if err != nil { panic(err) @@ -190,12 +185,9 @@ func (mc *MockClient) QuorumVerify( if err := quorumType.Validate(); err != nil { return false, err } - signID := crypto.SignID( - quorumType, - tmbytes.Reverse(quorumHash), - tmbytes.Reverse(requestID), - tmbytes.Reverse(messageHash), - ) + + signID := crypto.NewSignItemFromHash(quorumType, quorumHash, requestID, messageHash).ID + thresholdPublicKey, err := mc.localPV.GetThresholdPublicKey(context.Background(), quorumHash) if err != nil { panic(err) diff --git a/internal/consensus/vote_signer.go b/internal/consensus/vote_signer.go index ed50018955..a921b45615 100644 --- a/internal/consensus/vote_signer.go +++ b/internal/consensus/vote_signer.go @@ -108,7 +108,7 @@ func (s *voteSigner) signVote( if err != nil { return nil, err } - + s.logger.Debug("signed Vote", "vote", vote, "signature", vote.BlockSignature.String()) return vote, nil } diff --git a/internal/consensus/vote_signer_test.go b/internal/consensus/vote_signer_test.go index c8779698e5..0189e19f43 100644 --- a/internal/consensus/vote_signer_test.go +++ b/internal/consensus/vote_signer_test.go @@ -90,25 +90,25 @@ func TestVoteSigner_signAddVote(t *testing.T) { { msgType: tmproto.PrevoteType, blockID: blockID, - wantBlockSign: "8B52677D4D455125808EDEE715D2A999695A6701E477C1F44CEDCCE3FC62FB88698D0B6B3CA0429E17EDA9DBCEA932720C189E21F5A6FB31B2C244152F0CD7988598AD572E5D605164554C80880BDC130E23C9DBEF20CF315D05F8C13B6C92CC", + wantBlockSign: "80B628F02FE2047C7B98175CD8CF609775B95393C63D8EBC2F630D95121C28826C942F6511405D33484639C2906879110FDC293418C95862A60329FDDF0B210654559839B5ABFC11E50AFC4E498B0C9041118394DB04E52D0B28A92FC91DEABC", }, { msgType: tmproto.PrecommitType, - wantBlockSign: "97CCF337D8FCA05E600EAAF769D73BE9A0D1466CAE85374E9E0EF4C3DD1759131E1D2C8B9E8D8D28EBEF27074669D46C0820DF4DA337DFFA6B3EB5BEEA4B78CA8EA131ED584609D227025DB96990C732C2D04A693BC0402B8A19229ED32A51B8", + wantBlockSign: "8BEEE4EDA67394060C1A1D41797E998120B7BC217E7D36526DA76AE57616475FB1C4DCF08C522E76C75220104611F56800F1CF299ECD98FDB1C598471DC0D4048F8F5381B034270EB0B66E987D61B7DF555DFA92C6B5C9E6FAD608676130A726", }, { msgType: tmproto.PrecommitType, blockID: blockID, voteExtensions: nil, mockFn: mockFn, - wantBlockSign: "9755FA9803D98C344CB16A43B782D2A93ED9A7E7E1C8437482F42781D5EF802EC82442C14C44429737A7355B1F9D87CB139EB2CF193A1CF7C812E38B99221ADF4DAA60CE16550ED6509A9C467A3D4492D77038505235796968465337A1E14B3E", + wantBlockSign: "B2C484BB07094AAB8EFAB187982F6A8E8172FBEBAE5B6EB6304E527ABAAB7D059D9A43DDDBA82A6D296AF30E67C28D250449A586E9A69C2577057E01FA290BB03C186982D4D45E6016935AD4B9A84EB0911B62A83E457E25CE44DC28516D0E0A", }, { msgType: tmproto.PrecommitType, blockID: blockID, voteExtensions: voteExtensions, mockFn: mockFn, - wantBlockSign: "9755FA9803D98C344CB16A43B782D2A93ED9A7E7E1C8437482F42781D5EF802EC82442C14C44429737A7355B1F9D87CB139EB2CF193A1CF7C812E38B99221ADF4DAA60CE16550ED6509A9C467A3D4492D77038505235796968465337A1E14B3E", + wantBlockSign: "B2C484BB07094AAB8EFAB187982F6A8E8172FBEBAE5B6EB6304E527ABAAB7D059D9A43DDDBA82A6D296AF30E67C28D250449A586E9A69C2577057E01FA290BB03C186982D4D45E6016935AD4B9A84EB0911B62A83E457E25CE44DC28516D0E0A", }, } for i, tc := range testCases { diff --git a/privval/dash_consensus_key.go b/privval/dash_consensus_key.go index 5eb6a909d3..6fcf1be299 100644 --- a/privval/dash_consensus_key.go +++ b/privval/dash_consensus_key.go @@ -8,8 +8,8 @@ import ( "github.com/dashpay/dashd-go/btcjson" + "github.com/dashpay/tenderdash/crypto" tmcrypto "github.com/dashpay/tenderdash/crypto" - tmbytes "github.com/dashpay/tenderdash/libs/bytes" ) type dashConsensusPrivateKey struct { @@ -105,12 +105,7 @@ func (pub DashConsensusPublicKey) VerifySignature(msg []byte, sig []byte) bool { return pub.VerifySignatureDigest(hash, sig) } func (pub DashConsensusPublicKey) VerifySignatureDigest(hash []byte, sig []byte) bool { - signID := tmcrypto.SignID( - pub.quorumType, - tmbytes.Reverse(pub.quorumHash), - tmbytes.Reverse(hash[:]), - tmbytes.Reverse(hash[:]), - ) + signID := crypto.NewSignItemFromHash(pub.quorumType, pub.quorumHash, hash, hash).ID return pub.PubKey.VerifySignatureDigest(signID, sig) } diff --git a/privval/dash_core_signer_client.go b/privval/dash_core_signer_client.go index 775ede08eb..402a759b1d 100644 --- a/privval/dash_core_signer_client.go +++ b/privval/dash_core_signer_client.go @@ -292,7 +292,7 @@ func (sc *DashCoreSignerClient) SignVote( func (sc *DashCoreSignerClient) SignProposal( ctx context.Context, chainID string, quorumType btcjson.LLMQType, quorumHash crypto.QuorumHash, proposalProto *tmproto.Proposal, ) (tmbytes.HexBytes, error) { - signItem := types.NewSignItem( + signItem := crypto.NewSignItem( quorumType, quorumHash, types.ProposalRequestIDProto(proposalProto), @@ -314,7 +314,7 @@ func (sc *DashCoreSignerClient) QuorumSign( quorumType btcjson.LLMQType, quorumHash crypto.QuorumHash, ) ([]byte, []byte, error) { - signItem := types.NewSignItemFromHash(quorumType, quorumHash, requestIDHash, msgHash) + signItem := crypto.NewSignItemFromHash(quorumType, quorumHash, requestIDHash, msgHash) qs, err := sc.quorumSignAndVerify(ctx, quorumType, quorumHash, signItem) if err != nil { @@ -392,7 +392,7 @@ func (sc *DashCoreSignerClient) quorumSignAndVerify( ctx context.Context, quorumType btcjson.LLMQType, quorumHash crypto.QuorumHash, - signItem types.SignItem, + signItem crypto.SignItem, ) (*quorumSignResult, error) { qs, err := sc.quorumSign(quorumType, quorumHash, signItem) if err != nil { @@ -420,7 +420,7 @@ func (sc *DashCoreSignerClient) quorumSignAndVerify( func (sc *DashCoreSignerClient) quorumSign( quorumType btcjson.LLMQType, quorumHash crypto.QuorumHash, - signItem types.SignItem, + signItem crypto.SignItem, ) (*quorumSignResult, error) { resp, err := sc.dashCoreRPCClient.QuorumSign(quorumType, signItem.ReqID, signItem.Hash, quorumHash) if err != nil { diff --git a/test/e2e/pkg/mockcoreserver/core_server.go b/test/e2e/pkg/mockcoreserver/core_server.go index 9a3880f837..183929f228 100644 --- a/test/e2e/pkg/mockcoreserver/core_server.go +++ b/test/e2e/pkg/mockcoreserver/core_server.go @@ -9,7 +9,6 @@ import ( "github.com/dashpay/dashd-go/btcjson" "github.com/dashpay/tenderdash/crypto" - tmbytes "github.com/dashpay/tenderdash/libs/bytes" "github.com/dashpay/tenderdash/privval" ) @@ -93,13 +92,8 @@ func (c *MockCoreServer) QuorumSign(ctx context.Context, cmd btcjson.QuorumCmd) panic(err) } quorumHash := crypto.QuorumHash(quorumHashBytes) + signID := crypto.NewSignItemFromHash(*cmd.LLMQType, quorumHash, reqID, msgHash).ID - signID := crypto.SignID( - *cmd.LLMQType, - tmbytes.Reverse(quorumHash), - tmbytes.Reverse(reqID), - tmbytes.Reverse(msgHash), - ) privateKey, err := c.FilePV.GetPrivateKey(ctx, quorumHash) if err != nil { panic(err) @@ -142,13 +136,8 @@ func (c *MockCoreServer) QuorumVerify(ctx context.Context, cmd btcjson.QuorumCmd if err != nil { panic(err) } + signID := crypto.NewSignItemFromHash(*cmd.LLMQType, quorumHash, reqID, msgHash).ID - signID := crypto.SignID( - *cmd.LLMQType, - tmbytes.Reverse(quorumHash), - tmbytes.Reverse(reqID), - tmbytes.Reverse(msgHash), - ) thresholdPublicKey, err := c.FilePV.GetThresholdPublicKey(ctx, quorumHash) if err != nil { panic(err) diff --git a/types/proposal.go b/types/proposal.go index 9525556a0b..04c4fe26c7 100644 --- a/types/proposal.go +++ b/types/proposal.go @@ -182,12 +182,7 @@ func ProposalBlockSignID( proposalRequestID := ProposalRequestIDProto(p) - signID := crypto.SignID( - quorumType, - tmbytes.Reverse(quorumHash), - tmbytes.Reverse(proposalRequestID), - tmbytes.Reverse(proposalMessageHash[:]), - ) + signID := crypto.NewSignItemFromHash(quorumType, quorumHash, proposalRequestID, proposalMessageHash[:]).ID return signID } diff --git a/types/quorum_sign_data.go b/types/quorum_sign_data.go index 2d2ee9afd9..1f4617fe8b 100644 --- a/types/quorum_sign_data.go +++ b/types/quorum_sign_data.go @@ -4,10 +4,8 @@ import ( "bytes" "errors" "fmt" - "testing" "github.com/dashpay/dashd-go/btcjson" - "github.com/rs/zerolog" "github.com/dashpay/tenderdash/crypto" "github.com/dashpay/tenderdash/proto/tendermint/types" @@ -19,8 +17,8 @@ var ( // QuorumSignData holds data which is necessary for signing and verification block, state, and each vote-extension in a list type QuorumSignData struct { - Block SignItem - Extensions map[types.VoteExtensionType][]SignItem + Block crypto.SignItem + Extensions map[types.VoteExtensionType][]crypto.SignItem } // Verify verifies a quorum signatures: block, state and vote-extensions @@ -28,42 +26,6 @@ func (q QuorumSignData) Verify(pubKey crypto.PubKey, signs QuorumSigns) error { return NewQuorumSignsVerifier(q).Verify(pubKey, signs) } -// SignItem represents quorum sign data, like a request id, message bytes, sha256 hash of message and signID -type SignItem struct { - ReqID []byte // Request ID for quorum signing - ID []byte // Signature ID - Raw []byte // Raw data to be signed - Hash []byte // Checksum of Raw - QuorumType btcjson.LLMQType // Quorum type for which this sign item is created - QuorumHash []byte // Quorum hash for which this sign item is created -} - -// Validate validates prepared data for signing -func (i *SignItem) Validate() error { - if len(i.ReqID) != crypto.DefaultHashSize { - return fmt.Errorf("invalid request ID size: %X", i.ReqID) - } - if len(i.Hash) != crypto.DefaultHashSize { - return fmt.Errorf("invalid hash size: %X", i.ReqID) - } - if len(i.QuorumHash) != crypto.DefaultHashSize { - return fmt.Errorf("invalid quorum hash size: %X", i.ReqID) - } - if len(i.Raw) > 0 { - if !bytes.Equal(crypto.Checksum(i.Raw), i.Hash) { - return fmt.Errorf("invalid hash %X for raw data: %X", i.Hash, i.Raw) - } - } - return nil -} - -func (i SignItem) MarshalZerologObject(e *zerolog.Event) { - e.Hex("signBytes", i.Raw) - e.Hex("signRequestID", i.ReqID) - e.Hex("signID", i.ID) - e.Hex("signHash", i.Hash) -} - // MakeQuorumSignsWithVoteSet creates and returns QuorumSignData struct built with a vote-set and an added vote func MakeQuorumSignsWithVoteSet(voteSet *VoteSet, vote *types.Vote) (QuorumSignData, error) { return MakeQuorumSigns( @@ -94,13 +56,13 @@ func MakeQuorumSigns( } // MakeBlockSignItem creates SignItem struct for a block -func MakeBlockSignItem(chainID string, vote *types.Vote, quorumType btcjson.LLMQType, quorumHash []byte) SignItem { +func MakeBlockSignItem(chainID string, vote *types.Vote, quorumType btcjson.LLMQType, quorumHash []byte) crypto.SignItem { reqID := BlockRequestID(vote.Height, vote.Round) raw, err := vote.SignBytes(chainID) if err != nil { panic(fmt.Errorf("block sign item: %w", err)) } - return NewSignItem(quorumType, quorumHash, reqID, raw) + return crypto.NewSignItem(quorumType, quorumHash, reqID, raw) } // BlockRequestID returns a block request ID @@ -114,7 +76,7 @@ func MakeVoteExtensionSignItems( protoVote *types.Vote, quorumType btcjson.LLMQType, quorumHash []byte, -) (map[types.VoteExtensionType][]SignItem, error) { +) (map[types.VoteExtensionType][]crypto.SignItem, error) { // We only sign vote extensions for precommits if protoVote.Type != types.PrecommitType { if len(protoVote.VoteExtensions) > 0 { @@ -122,11 +84,11 @@ func MakeVoteExtensionSignItems( } return nil, nil } - items := make(map[types.VoteExtensionType][]SignItem) + items := make(map[types.VoteExtensionType][]crypto.SignItem) protoExtensionsMap := protoVote.VoteExtensionsToMap() for t, exts := range protoExtensionsMap { if items[t] == nil && len(exts) > 0 { - items[t] = make([]SignItem, len(exts)) + items[t] = make([]crypto.SignItem, len(exts)) } for i, ext := range exts { @@ -139,72 +101,12 @@ func MakeVoteExtensionSignItems( if ext.Type == types.VoteExtensionType_THRESHOLD_RECOVER_RAW { // for this vote extension type, we just sign raw data from extension msgHash := bytes.Clone(raw) - items[t][i] = NewSignItemFromHash(quorumType, quorumHash, reqID, msgHash) + items[t][i] = crypto.NewSignItemFromHash(quorumType, quorumHash, reqID, msgHash) items[t][i].Raw = raw } else { - items[t][i] = NewSignItem(quorumType, quorumHash, reqID, raw) + items[t][i] = crypto.NewSignItem(quorumType, quorumHash, reqID, raw) } } } return items, nil } - -// NewSignItem creates a new instance of SignItem with calculating a hash for a raw and creating signID -// -// Arguments: -// - quorumType: quorum type -// - quorumHash: quorum hash -// - reqID: sign request ID -// - raw: raw data to be signed; it will be hashed with crypto.Checksum() -func NewSignItem(quorumType btcjson.LLMQType, quorumHash, reqID, raw []byte) SignItem { - msgHash := crypto.Checksum(raw) - item := NewSignItemFromHash(quorumType, quorumHash, reqID, msgHash) - item.Raw = raw - - return item -} - -// Create a new sign item without raw value, using provided hash. -func NewSignItemFromHash(quorumType btcjson.LLMQType, quorumHash, reqID, msgHash []byte) SignItem { - item := SignItem{ - ReqID: reqID, - Hash: msgHash, - QuorumType: quorumType, - QuorumHash: quorumHash, - Raw: nil, // Raw is empty, as we don't have it - } - item.UpdateID() - - return item -} - -func (i *SignItem) UpdateID() { - if err := i.Validate(); err != nil { - panic("invalid sign item: " + err.Error()) - } - // FIXME: previously we had reversals, but this doesn't work with Core test vectors - // So - // quorumHash := tmbytes.Reverse(i.QuorumHash) - quorumHash := i.QuorumHash - // requestID := tmbytes.Reverse(i.ReqID) - requestID := i.ReqID - // messageHash := tmbytes.Reverse(i.Hash) - messageHash := i.Hash - - if testing.Testing() { - fmt.Printf("generating sign ID using bls.BuildSignHash for %d %X %X %X\n", i.QuorumType, quorumHash, requestID, messageHash) - out := append([]byte{byte(i.QuorumType)}, quorumHash...) - out = append(out, requestID...) - out = append(out, messageHash...) - - fmt.Printf("data before sha256: %X\n", out) - fmt.Printf("sha256(sha256(data)): %X\n", crypto.Checksum((crypto.Checksum(out)))) - - } - i.ID = crypto.SignID( - i.QuorumType, - quorumHash, - requestID, - messageHash, - ) -} diff --git a/types/quorum_sign_data_test.go b/types/quorum_sign_data_test.go index 6628b33b26..68e6b97236 100644 --- a/types/quorum_sign_data_test.go +++ b/types/quorum_sign_data_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/dashpay/tenderdash/crypto" tmbytes "github.com/dashpay/tenderdash/libs/bytes" "github.com/dashpay/tenderdash/libs/log" "github.com/dashpay/tenderdash/proto/tendermint/types" @@ -26,7 +27,7 @@ func TestMakeBlockSignID(t *testing.T) { testCases := []struct { vote Vote quorumHash []byte - want SignItem + want crypto.SignItem wantHash []byte }{ { @@ -63,7 +64,7 @@ func TestMakeVoteExtensionSignsData(t *testing.T) { testCases := []struct { vote Vote quorumHash []byte - want map[types.VoteExtensionType][]SignItem + want map[types.VoteExtensionType][]crypto.SignItem wantHash map[types.VoteExtensionType][][]byte }{ { @@ -81,7 +82,7 @@ func TestMakeVoteExtensionSignsData(t *testing.T) { }, }, quorumHash: tmbytes.MustHexDecode("6A12D9CF7091D69072E254B297AEF15997093E480FDE295E09A7DE73B31CEEDD"), - want: map[types.VoteExtensionType][]SignItem{ + want: map[types.VoteExtensionType][]crypto.SignItem{ types.VoteExtensionType_DEFAULT: { newSignItem( "FB95F2CA6530F02AC623589D7938643FF22AE79A75DD79AEA1C8871162DE675E", @@ -184,8 +185,8 @@ func TestVoteExtensionsRawSignDataRawVector(t *testing.T) { } -func newSignItem(reqID, ID, raw, quorumHash string, quorumType btcjson.LLMQType) SignItem { - item := NewSignItem(quorumType, tmbytes.MustHexDecode(quorumHash), tmbytes.MustHexDecode(reqID), tmbytes.MustHexDecode(raw)) +func newSignItem(reqID, ID, raw, quorumHash string, quorumType btcjson.LLMQType) crypto.SignItem { + item := crypto.NewSignItem(quorumType, tmbytes.MustHexDecode(quorumHash), tmbytes.MustHexDecode(reqID), tmbytes.MustHexDecode(raw)) item.ID = tmbytes.MustHexDecode(ID) return item }