Skip to content

Commit

Permalink
linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht committed Sep 19, 2024
1 parent 23fc2cc commit 2296386
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/matrix/msg_assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions pkg/cheques/eth_typed_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions pkg/cheques/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ var (
}
)

type ChequesSigner interface {

Check failure on line 38 in pkg/cheques/signer.go

View workflow job for this annotation

GitHub Actions / Static Analysis

exported: type name will be used as cheques.ChequesSigner by other packages, and that stutters; consider calling this Signer (revive)
SignCheque(cheque *Cheque) (*SignedCheque, error)
}

type chequeSigner struct {
privateKey *ecdsa.PrivateKey
domainSeparator []byte
chequeTypeHash []byte
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",
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit 2296386

Please sign in to comment.