Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ jobs:
with:
go-version-file: "go.mod"

- name: Set up tools
run: make install-linter-tool

- name: Checks
run: make checks

- name: Run linter
run: make lint

- name: Legacy guard
run: |
# Fail if new files import dlog or weak-bb outside known locations.
Expand Down Expand Up @@ -59,7 +65,7 @@ jobs:
bin/

- name: Release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
bin
/.bob/
/.idea/
164 changes: 164 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
version: "2"
linters:
enable:
- asasalint # Check for pass []any as any in variadic func(...any).
- canonicalheader # Canonicalheader checks whether net/http.Header uses canonical header. [auto-fix]
- copyloopvar # A linter detects places where loop variables are copied. [fast, auto-fix]
- depguard # Go linter that checks if package imports are in a list of acceptable packages. [fast]
- dupword # Checks for duplicate words in the source code. [fast, auto-fix]
- durationcheck # Check for two durations multiplied together.
- errorlint # Find code that can cause problems with the error wrapping scheme introduced in Go 1.13. [auto-fix]
- exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. [auto-fix]
- ginkgolinter # Enforces standards of using ginkgo and gomega. [auto-fix]
- goheader # Check if file header matches to pattern. [fast, auto-fix]
- gosec # Inspects source code for security problems.
- govet # Vet examines Go source code and reports suspicious constructs. It is roughly the same as 'go vet' and uses its passes. [auto-fix]
- importas # Enforces consistent import aliases. [auto-fix]
- intrange # Intrange is a linter to find places where for loops could make use of an integer range. [auto-fix]
- loggercheck # Checks key value pairs for common logger libraries (kitlog,klog,logr,slog,zap).
- mirror # Reports wrong mirror patterns of bytes/strings usage. [auto-fix]
- misspell # Finds commonly misspelled English words. [fast, auto-fix]
- nakedret # Checks that functions with naked returns are not longer than a maximum size (can be zero). [fast, auto-fix]
- nilerr # Find the code that returns nil even if it checks that the error is not nil.
- nilnesserr # Reports constructs that checks for err != nil, but returns a different nil value error.
- nlreturn # Checks for a new line before return and branch statements to increase code clarity. [fast, auto-fix]
- nolintlint # Reports ill-formed or insufficient nolint directives. [fast, auto-fix]
- perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. [auto-fix]
- reassign # Checks that package variables are not reassigned.
- sloglint # Ensure consistent code style when using log/slog. [auto-fix]
- spancheck # Checks for mistakes with OpenTelemetry/Census spans.
- staticcheck # It's the set of rules from staticcheck. [auto-fix]
- tagalign # Check that struct tags are well aligned. [fast, auto-fix]
- testifylint # Checks usage of github.com/stretchr/testify. [auto-fix]
- thelper # Thelper detects tests helpers which do not start with the t.Helper() method.
- unconvert # Remove unnecessary type conversions.
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. [fast, auto-fix]
- usetesting # Reports uses of functions with replacement inside the testing package. [auto-fix]
- wastedassign # Finds wasted assignment statements.
- whitespace # Whitespace is a linter that checks for unnecessary newlines at the start and end of functions, if, for, etc. [fast, auto-fix]
- zerologlint # Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg`.
settings:
depguard:
rules:
main:
deny:
- pkg: github.com/pkg/errors
desc: github.com/pkg/errors is no longer maintained
errcheck:
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
check-type-assertions: false
errorlint:
# Check whether fmt.Errorf uses the %w verb for formatting errors.
errorf: true
# Check for plain type assertions and type switches.
asserts: false
# Check for plain error comparisons.
comparison: true
fatcontext:
check-struct-pointers: true
gocognit:
min-complexity: 15
gosec:
excludes:
- G204
- G404
- G306
govet:
disable:
- fieldalignment
# Enable all analyzers.
enable-all: false
iface:
enable:
- identical # Identifies interfaces in the same package that have identical method sets.
- unused # Identifies interfaces that are not used anywhere in the same package where the interface is defined.
- opaque # Identifies functions that return interfaces, but the actual returned value is always a single concrete implementation.
ireturn:
# By default, it allows using errors, empty interfaces, anonymous interfaces,
# and interfaces provided by the standard library.
allow:
- error
- empty
- anon
- stdlib
- generic
- (or|er)$
- T
- github.com/prometheus/client_golang/prometheus.Counter
- github.com/prometheus/client_golang/prometheus.Gauge
- github.com/prometheus/client_golang/prometheus.Histogram
lll:
# Max line length, lines longer will be reported.
line-length: 240
maintidx:
under: 20
nolintlint:
require-specific: true
revive:
enable-all-rules: true
rules:
- name: argument-limit
arguments:
- 5
- name: line-length-limit
arguments:
- 240
- name: file-header
disabled: true
- name: package-comments
disabled: true
- name: max-public-structs
disabled: true
- name: banned-characters
disabled: true
- name: cognitive-complexity
disabled: true
- name: cyclomatic
disabled: true
- name: function-length
disabled: true
- name: function-result-limit
arguments:
- 3
- name: add-constant
disabled: true
- name: unhandled-error
arguments:
- fmt.Printf
- fmt.Println
- name: confusing-naming
disabled: true
- name: comment-spacings
arguments:
- 'nolint:'
rowserrcheck:
packages:
- github.com/jackc/pgx/v5
- github.com/jackc/pgx/v4
wrapcheck:
# An array of strings specifying additional substrings of signatures to ignore.
extra-ignore-sigs:
- .CustomError(
- .SpecificWrap(

# An array of strings that specify substrings of signatures to ignore.
ignore-sigs:
- errors.New(
- errors.Newf(
- errors.Unwrap(
- errors.Join(
- .Wrap(
- .Wrapf(
- status.Error(
- .Wait() # The error reported by errorgroup.Wait() (external) actually originates from the internal code.
# An array of strings that specify regular expressions of signatures to ignore.
ignore-sig-regexps:
- \.New.*Error\(
exclusions:
# Mode of the generated files analysis.
generated: lax
# Log a warning if an exclusion rule is unused.
warn-unused: true
# Predefined exclusion rules.
presets:
- common-false-positives
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,21 @@ fmt: ## Run gofmt on the entire project
# tidy up go modules
tidy:
@go mod tidy

.PHONY: lint
# run various linters
lint:
@echo "Running Go Linters..."
golangci-lint run --color=always --timeout=4m

.PHONY: lint-auto-fix
# run linters with auto-fix
lint-auto-fix:
@echo "Running Go Linters with auto-fix..."
golangci-lint run --color=always --timeout=4m --fix

.PHONY: install-linter-tool
# install golangci-lint
install-linter-tool:
@echo "Installing golangci Linter"
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(HOME)/go/bin v2.12.2
5 changes: 1 addition & 4 deletions bbs/bbs12381g2pub.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func (bbs *BBSG2Pub) Sign(messages [][]byte, privKeyBytes []byte) ([]byte, error

// VerifyProof verifies BBS+ signature proof for one ore more revealed messages.
func (bbs *BBSG2Pub) VerifyProof(messagesBytes [][]byte, proof, nonce, pubKeyBytes []byte) error {

messages := MessagesToFr(messagesBytes, bbs.curve)

return bbs.VerifyProofFr(messages, proof, nonce, pubKeyBytes)
Expand Down Expand Up @@ -140,7 +139,7 @@ func (bbs *BBSG2Pub) VerifyProofFr(messages []*SignatureMessage, proof, nonce, p
}

if len(payload.Revealed) > len(messages) {
return fmt.Errorf("payload revealed bigger from messages")
return errors.New("payload revealed bigger from messages")
}

revealedMessages := make(map[int]*SignatureMessage)
Expand All @@ -160,15 +159,13 @@ func (bbs *BBSG2Pub) VerifyProofFr(messages []*SignatureMessage, proof, nonce, p
// DeriveProof derives a proof of BBS+ signature with some messages disclosed.
func (bbs *BBSG2Pub) DeriveProof(messages [][]byte, sigBytes, nonce, pubKeyBytes []byte,
revealedIndexes []int) ([]byte, error) {

return bbs.DeriveProofZr(MessagesToFr(messages, bbs.curve), sigBytes, nonce, pubKeyBytes, revealedIndexes)
}

// DeriveProofZr derives a proof of BBS+ signature with some messages disclosed.
// The messages are supplied as scalars and not bytes.
func (bbs *BBSG2Pub) DeriveProofZr(messagesFr []*SignatureMessage, sigBytes, nonce, pubKeyBytes []byte,
revealedIndexes []int) ([]byte, error) {

if len(revealedIndexes) == 0 {
return nil, errors.New("no message to reveal")
}
Expand Down
10 changes: 4 additions & 6 deletions bbs/bbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package bbs_test
import (
"crypto/rand"
"encoding/base64"
"fmt"
"testing"

"github.com/IBM/idemix/bbs"
Expand Down Expand Up @@ -78,7 +77,7 @@ func TestBlsG2Pub_Verify(t *testing.T) {

func TestBBSG2Pub_SignWithKeyPair(t *testing.T) {
for i, c := range ml.Curves {
t.Run(fmt.Sprintf("with curve %s", ml.CurveIDToString(ml.CurveID(i))), func(t *testing.T) {
t.Run("with curve "+ml.CurveIDToString(ml.CurveID(i)), func(t *testing.T) {
pubKey, privKey, err := generateKeyPairRandom(c)
require.NoError(t, err)

Expand All @@ -101,7 +100,7 @@ func TestBBSG2Pub_SignWithKeyPair(t *testing.T) {

func TestBBSG2Pub_Sign(t *testing.T) {
for i, curve := range ml.Curves {
t.Run(fmt.Sprintf("with curve %s", ml.CurveIDToString(ml.CurveID(i))), func(t *testing.T) {
t.Run("with curve "+ml.CurveIDToString(ml.CurveID(i)), func(t *testing.T) {
pubKey, privKey, err := generateKeyPairRandom(curve)
require.NoError(t, err)

Expand Down Expand Up @@ -231,7 +230,7 @@ func TestBBSG2Pub_VerifyProof_SeveralDisclosedMessages(t *testing.T) {

func TestBBSG2Pub_DeriveProof(t *testing.T) {
for i, curve := range ml.Curves {
t.Run(fmt.Sprintf("with curve %s", ml.CurveIDToString(ml.CurveID(i))), func(t *testing.T) {
t.Run("with curve "+ml.CurveIDToString(ml.CurveID(i)), func(t *testing.T) {
pubKey, privKey, err := generateKeyPairRandom(curve)
require.NoError(t, err)

Expand Down Expand Up @@ -288,8 +287,7 @@ func TestBBSG2Pub_DeriveProof(t *testing.T) {
// signer doesn't check the well-formedness of the term received from the requester
func TestBlindSign(t *testing.T) {
for i, curve := range ml.Curves {
t.Run(fmt.Sprintf("with curve %s", ml.CurveIDToString(ml.CurveID(i))), func(t *testing.T) {

t.Run("with curve "+ml.CurveIDToString(ml.CurveID(i)), func(t *testing.T) {
pubKey, privKey, err := generateKeyPairRandom(curve)
require.NoError(t, err)

Expand Down
Loading
Loading