From 265b3424d0f3a12d541fd071b2f816b46ff025db Mon Sep 17 00:00:00 2001 From: Satchmo Date: Tue, 17 Sep 2024 07:08:12 -0400 Subject: [PATCH] update linter version, add lint exceptions for gosec, update change log --- .github/workflows/golangci-lint.yaml | 4 ++-- .golangci.yml | 9 +++++++-- CHANGELOG.md | 12 ++++++++++++ primitives/hash/hash.go | 4 ++-- script/interpreter/operations.go | 6 +++--- transaction/merklepath.go | 4 ++-- transaction/merklepath_test.go | 12 ++++++------ transaction/transaction_test.go | 2 +- util/bytemanipulation_test.go | 1 - 9 files changed, 35 insertions(+), 19 deletions(-) diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml index 8c52c20..d1a6536 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci-lint.yaml @@ -9,8 +9,8 @@ on: - "master" env: - GO_VERSION: '1.22' # Use the version you need - GOLANGCI_LINT_VERSION: v1.59 # Latest version as of my last update + GO_VERSION: '1.22' + GOLANGCI_LINT_VERSION: v1.60.1 jobs: detect-modules: diff --git a/.golangci.yml b/.golangci.yml index d1e8892..3986c76 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -196,7 +196,7 @@ linters-settings: checks: # the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description. argument,case,condition,operation,return,assign - + govet: # report about shadowed variables shadow: true @@ -336,7 +336,7 @@ linters: - dogsled # - revive - prealloc - - exportloopref + - copyloopvar - exhaustive - sqlclosecheck - nolintlint @@ -398,6 +398,11 @@ issues: - staticcheck text: "SA1019:" + # Exclude some gosec messages + - linters: + - gosec + text: "G115:" + # Exclude lll issues for long lines with go:generate - linters: - lll diff --git a/CHANGELOG.md b/CHANGELOG.md index 201d2d1..ba99060 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. The format ## Table of Contents - [Unreleased](#unreleased) +- [1.1.8 - 2024-09-17](#118---2024-09-17) - [1.1.7 - 2024-09-10](#117---2024-09-10) - [1.1.6 - 2024-09-09](#116---2024-09-09) - [1.1.5 - 2024-09-06](#115---2024-09-06) @@ -16,6 +17,17 @@ All notable changes to this project will be documented in this file. The format - [1.0.0 - 2024-06-06](#100---2024-06-06) +## [1.1.8] - 2024-09-17 + ### Changed + - Restore Transaction `Clone` to its previous state, and add `ShallowClone` as a more efficient alternative + - Fix the version number bytes in `message` + - Rename `merkleproof.ToHex()` to `Hex()` + - Update golangci-lint version and rules + + ### Added + - `transaction.ShallowClone` + - `transaction.Hex` + ## [1.1.7] - 2024-09-10 - Rework `tx.Clone()` to be more efficient - Introduce SignUnsigned to sign only inputs that have not already been signed diff --git a/primitives/hash/hash.go b/primitives/hash/hash.go index b0585c2..6e03f80 100644 --- a/primitives/hash/hash.go +++ b/primitives/hash/hash.go @@ -5,7 +5,7 @@ import ( "crypto/sha256" "crypto/sha512" - "golang.org/x/crypto/ripemd160" + "golang.org/x/crypto/ripemd160" //nolint:gosec // required ) // Sha256 calculates hash(b) and returns the resulting bytes. @@ -42,7 +42,7 @@ func Sha512HMAC(b, key []byte) []byte { // Ripemd160 hashes with RIPEMD160 func Ripemd160(b []byte) []byte { - ripe := ripemd160.New() + ripe := ripemd160.New() //nolint:gosec // required _, _ = ripe.Write(b[:]) return ripe.Sum(nil) } diff --git a/script/interpreter/operations.go b/script/interpreter/operations.go index c0b2026..0087974 100644 --- a/script/interpreter/operations.go +++ b/script/interpreter/operations.go @@ -7,7 +7,7 @@ import ( "hash" "math/big" - "golang.org/x/crypto/ripemd160" + "golang.org/x/crypto/ripemd160" //nolint:gosec // required ec "github.com/bitcoin-sv/go-sdk/primitives/ec" crypto "github.com/bitcoin-sv/go-sdk/primitives/hash" @@ -1869,7 +1869,7 @@ func opcodeRipemd160(op *ParsedOpcode, t *thread) error { return err } - t.dstack.PushByteArray(calcHash(buf, ripemd160.New())) + t.dstack.PushByteArray(calcHash(buf, ripemd160.New())) //nolint:gosec // required return nil } @@ -1914,7 +1914,7 @@ func opcodeHash160(op *ParsedOpcode, t *thread) error { } hash := sha256.Sum256(buf) - t.dstack.PushByteArray(calcHash(hash[:], ripemd160.New())) + t.dstack.PushByteArray(calcHash(hash[:], ripemd160.New())) //nolint:gosec // required return nil } diff --git a/transaction/merklepath.go b/transaction/merklepath.go index 2e4aaf8..32d3f0f 100644 --- a/transaction/merklepath.go +++ b/transaction/merklepath.go @@ -186,8 +186,8 @@ func (mp *MerklePath) Bytes() []byte { return bytes } -// ToHex converts the MerklePath to a hexadecimal string representation -func (mp *MerklePath) ToHex() string { +// Hex converts the MerklePath to a hexadecimal string representation +func (mp *MerklePath) Hex() string { return hex.EncodeToString(mp.Bytes()) } diff --git a/transaction/merklepath_test.go b/transaction/merklepath_test.go index f385f2a..ca36412 100644 --- a/transaction/merklepath_test.go +++ b/transaction/merklepath_test.go @@ -55,17 +55,17 @@ var BRC74JSON = MerklePath{ var BRC74JSONTrimmed = `{"blockHeight":813706,"path":[[{"offset":3048,"hash":"304e737fdfcb017a1a322e78b067ecebb5e07b44f0a36ed1f01264d2014f7711"},{"offset":3049,"hash":"d888711d588021e588984e8278a2decf927298173a06737066e43f3e75534e00","txid":true},{"offset":3050,"hash":"98c9c5dd79a18f40837061d5e0395ffb52e700a2689e641d19f053fc9619445e","txid":true},{"offset":3051,"duplicate":true}],[],[{"offset":763,"duplicate":true}],[{"offset":380,"hash":"858e41febe934b4cbc1cb80a1dc8e254cb1e69acff8e4f91ecdd779bcaefb393"}],[{"offset":191,"duplicate":true}],[{"offset":94,"hash":"f80263e813c644cd71bcc88126d0463df070e28f11023a00543c97b66e828158"}],[{"offset":46,"hash":"f36f792fa2b42acfadfa043a946d4d7b6e5e1e2e0266f2cface575bbb82b7ae0"}],[{"offset":22,"hash":"7d5051f0d4ceb7d2e27a49e448aedca2b3865283ceffe0b00b9c3017faca2081"}],[{"offset":10,"hash":"43aeeb9b6a9e94a5a787fbf04380645e6fd955f8bf0630c24365f492ac592e50"}],[{"offset":4,"hash":"45be5d16ac41430e3589a579ad780e5e42cf515381cc309b48d0f4648f9fcd1c"}],[{"offset":3,"duplicate":true}],[{"offset":0,"hash":"d40cb31af3ef53dd910f5ce15e9a1c20875c009a22d25eab32c11c7ece6487af"}]]}` -func TestMerklePath_ParseHex(t *testing.T) { +func TestMerklePathParseHex(t *testing.T) { t.Parallel() t.Run("parses from hex", func(t *testing.T) { mp, err := NewMerklePathFromHex(BRC74Hex) require.NoError(t, err) - require.Equal(t, BRC74Hex, mp.ToHex()) + require.Equal(t, BRC74Hex, mp.Hex()) }) } -func TestMerklePath_ToHex(t *testing.T) { +func TestMerklePathToHex(t *testing.T) { // t.Parallel() t.Run("serializes to hex", func(t *testing.T) { @@ -73,12 +73,12 @@ func TestMerklePath_ToHex(t *testing.T) { BlockHeight: BRC74JSON.BlockHeight, Path: BRC74JSON.Path, } - hex := path.ToHex() + hex := path.Hex() require.Equal(t, BRC74Hex, hex) }) } -func TestMerklePath_ComputeRootHex(t *testing.T) { +func TestMerklePathComputeRootHex(t *testing.T) { t.Parallel() t.Run("computes a root", func(t *testing.T) { @@ -120,7 +120,7 @@ func TestMerklePath_Verify(t *testing.T) { } -func TestMerklePath_Combine(t *testing.T) { +func TestMerklePathCombine(t *testing.T) { t.Parallel() t.Run("combines two paths", func(t *testing.T) { diff --git a/transaction/transaction_test.go b/transaction/transaction_test.go index ee49552..9252bdb 100644 --- a/transaction/transaction_test.go +++ b/transaction/transaction_test.go @@ -185,6 +185,6 @@ func TestSignUnsignedNew(t *testing.T) { require.NoError(t, err) for _, input := range tx.Inputs { - require.Positive(t, len(input.UnlockingScript.Bytes())) + require.NotEmpty(t, input.UnlockingScript.Bytes()) } } diff --git a/util/bytemanipulation_test.go b/util/bytemanipulation_test.go index 5d1497c..e27bc12 100644 --- a/util/bytemanipulation_test.go +++ b/util/bytemanipulation_test.go @@ -58,7 +58,6 @@ func TestLittleEndianBytes(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() result := util.LittleEndianBytes(tc.input, tc.length)