Skip to content

Commit

Permalink
resolve linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rohenaz committed Aug 27, 2024
1 parent 0f4d1f7 commit 564cdbe
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
8 changes: 3 additions & 5 deletions primitives/ec/privatekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (p *PrivateKey) ToKeyShares(threshold int, totalShares int) (keyShares *sha
if totalShares < 2 {
return nil, errors.New("totalShares must be at least 2")
}
if threshold > int(totalShares) {
if threshold > totalShares {
return nil, errors.New("threshold should be less than or equal to totalShares")
}

Expand All @@ -256,7 +256,7 @@ func (p *PrivateKey) ToKeyShares(threshold int, totalShares int) (keyShares *sha
return nil, err
}

var points []*shamir.PointInFiniteField
points := make([]*shamir.PointInFiniteField, 0)
for range totalShares {
pk, err := NewPrivateKey()
if err != nil {
Expand Down Expand Up @@ -301,10 +301,8 @@ func PrivateKeyFromKeyShares(keyShares *shamir.KeyShares) (*PrivateKey, error) {
// check to see if two points have the same x value
for i := 0; i < keyShares.Threshold; i++ {
for j := i + 1; j < keyShares.Threshold; j++ {
fmt.Printf("Comparing X values: Point %d (X: %s) and Point %d (X: %s)\n", i, keyShares.Points[i].X.String(), j, keyShares.Points[j].X.String())
if keyShares.Points[i].X.Cmp(keyShares.Points[j].X) == 0 {
fmt.Printf("Detected duplicate X value at indices %d and %d with values %s and %s\n", i, j, keyShares.Points[i].X.String(), keyShares.Points[j].X.String())
return nil, fmt.Errorf("duplicate share detected, each must be unique: %d (%s) and %d (%s)", i, keyShares.Points[i].X, j, keyShares.Points[j].X)
return nil, fmt.Errorf("duplicate share detected, each must be unique")
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions primitives/ec/privatekey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func TestPolynomialFromPrivateKey(t *testing.T) {
}
}

func TestFullProcess(t *testing.T) {
func TestPolynomialFullProcess(t *testing.T) {
// Create a private key
privateKey, err := NewPrivateKey()
if err != nil {
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestFullProcess(t *testing.T) {
}
}

func TestDifferentThresholdsAndShares(t *testing.T) {
func TestPolynomialDifferentThresholdsAndShares(t *testing.T) {
testCases := []struct {
threshold int
totalShares int
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestDifferentThresholdsAndShares(t *testing.T) {
}
}

func TestEdgeCases(t *testing.T) {
func TestPolynomialEdgeCases(t *testing.T) {
privateKey, _ := NewPrivateKey()

// Minimum threshold (2)
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestEdgeCases(t *testing.T) {
})
}

func TestReconstructionWithDifferentSubsets(t *testing.T) {
func TestPolynomialReconstructionWithDifferentSubsets(t *testing.T) {
privateKey, _ := NewPrivateKey()
threshold := 3
totalShares := 5
Expand Down Expand Up @@ -301,7 +301,7 @@ func TestReconstructionWithDifferentSubsets(t *testing.T) {
}
}

func TestErrorHandling(t *testing.T) {
func TestPolynomialErrorHandling(t *testing.T) {
privateKey, _ := NewPrivateKey()

// Test with invalid threshold (too low)
Expand All @@ -326,7 +326,7 @@ func TestErrorHandling(t *testing.T) {
}
}

func TestConsistency(t *testing.T) {
func TestPolynomialConsistency(t *testing.T) {
privateKey, _ := NewPrivateKey()
threshold := 3
totalShares := 5
Expand Down
2 changes: 1 addition & 1 deletion primitives/ec/publickey.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (p *PublicKey) Mul(k *big.Int) *PublicKey {
}
}

// TODO: Rename encode to ToHash to match ts-sdk
//nolint:unparam // only compact is used
func (p *PublicKey) encode(compact bool) []byte {
byteLen := (p.Curve.Params().BitSize + 7) >> 3

Expand Down
5 changes: 2 additions & 3 deletions primitives/shamir/keyshares.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type KeyShares struct {
func NewKeySharesFromBackupFormat(shares []string) (keyShares *KeyShares, error error) {
var threshold int = 0
var integrity string = ""
var points []*PointInFiniteField
points := make([]*PointInFiniteField, 0)
for idx, share := range shares {
shareParts := strings.Split(share, ".")
if len(shareParts) != 4 {
Expand Down Expand Up @@ -76,9 +76,8 @@ func NewKeySharesFromBackupFormat(shares []string) (keyShares *KeyShares, error
* @returns
*/
func (k *KeyShares) ToBackupFormat() ([]string, error) {
var backupShares []string
backupShares := make([]string, 0)
for _, share := range k.Points {

backupShares = append(backupShares, share.String()+"."+strconv.Itoa(k.Threshold)+"."+k.Integrity)
}
return backupShares, nil
Expand Down

0 comments on commit 564cdbe

Please sign in to comment.