From 2296386f3b8311f7eeb9dece6f3153de8cd404bf Mon Sep 17 00:00:00 2001 From: "ev.lekht" Date: Thu, 19 Sep 2024 17:37:26 +0400 Subject: [PATCH] linter fixes --- internal/matrix/msg_assembler.go | 2 +- pkg/cheques/eth_typed_data.go | 7 ++++--- pkg/cheques/signer.go | 10 +++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/internal/matrix/msg_assembler.go b/internal/matrix/msg_assembler.go index c45e4d19..fde31a6f 100644 --- a/internal/matrix/msg_assembler.go +++ b/internal/matrix/msg_assembler.go @@ -48,7 +48,7 @@ func (a *messageAssembler) AssembleMessage(msg *matrix.CaminoMatrixMessage) (*ma a.partialMessages[id] = append(a.partialMessages[id], msg) // TODO: I believe it's safe to assume the number of chunks will not overflow - // #nosec G115 + // TODO@ nosec G115 if len(a.partialMessages[id]) == int(msg.Metadata.NumberOfChunks) { decompressedCaminoMsg, err := a.assembleAndDecompressCaminoMatrixMessages(a.partialMessages[id]) delete(a.partialMessages, id) diff --git a/pkg/cheques/eth_typed_data.go b/pkg/cheques/eth_typed_data.go index a60d347d..221baa56 100644 --- a/pkg/cheques/eth_typed_data.go +++ b/pkg/cheques/eth_typed_data.go @@ -24,7 +24,8 @@ func hashStructWithTypeHash(typedData *apitypes.TypedData, dataType string, type for _, field := range typedData.Types[chequeType] { encType := field.Type encValue := typedData.Message[field.Name] - if encType[len(encType)-1:] == "]" { + switch { + case encType[len(encType)-1:] == "]": arrayValue, err := convertDataToSlice(encValue) if err != nil { return nil, dataMismatchError(encType, encValue) @@ -53,7 +54,7 @@ func hashStructWithTypeHash(typedData *apitypes.TypedData, dataType string, type } buffer.Write(crypto.Keccak256(arrayBuffer.Bytes())) - } else if typedData.Types[field.Type] != nil { + case typedData.Types[field.Type] != nil: mapValue, ok := encValue.(map[string]interface{}) if !ok { return nil, dataMismatchError(encType, encValue) @@ -63,7 +64,7 @@ func hashStructWithTypeHash(typedData *apitypes.TypedData, dataType string, type return nil, err } buffer.Write(crypto.Keccak256(encodedData)) - } else { + default: byteValue, err := typedData.EncodePrimitiveValue(encType, encValue, depth) if err != nil { return nil, err diff --git a/pkg/cheques/signer.go b/pkg/cheques/signer.go index 7900c525..4fd388f1 100644 --- a/pkg/cheques/signer.go +++ b/pkg/cheques/signer.go @@ -35,6 +35,10 @@ var ( } ) +type ChequesSigner interface { + SignCheque(cheque *Cheque) (*SignedCheque, error) +} + type chequeSigner struct { privateKey *ecdsa.PrivateKey domainSeparator []byte @@ -42,7 +46,7 @@ type chequeSigner struct { domain *apitypes.TypedDataDomain } -func NewChequeSigner(privateKey *ecdsa.PrivateKey, chainID *big.Int) (*chequeSigner, error) { +func NewChequeSigner(privateKey *ecdsa.PrivateKey, chainID *big.Int) (ChequesSigner, error) { domain := apitypes.TypedDataDomain{ Name: "CaminoMessenger", Version: "1", @@ -91,7 +95,7 @@ func (cs *chequeSigner) SignCheque(cheque *Cheque) (*SignedCheque, error) { typedDataHash, err := hashStructWithTypeHash(data, chequeType, cs.chequeTypeHash) if err != nil { - return nil, fmt.Errorf("failed to hash struct: %v", err) + return nil, fmt.Errorf("failed to hash struct: %w", err) } finalHash := crypto.Keccak256( @@ -102,7 +106,7 @@ func (cs *chequeSigner) SignCheque(cheque *Cheque) (*SignedCheque, error) { signature, err := crypto.Sign(finalHash, cs.privateKey) if err != nil { - return nil, fmt.Errorf("failed to sign the hash: %v", err) + return nil, fmt.Errorf("failed to sign the hash: %w", err) } // adjust recovery byte for compatibility