Skip to content
This repository was archived by the owner on Jan 28, 2026. It is now read-only.

Commit 70c8c5b

Browse files
committed
refactor: remove unneeded methods, tests | err check fix
Removed the `SignatureBytesToHex` since its just a wrapper on std hex lib method and refactored where needed. Removed failure tests for `HexToECDSA` and `FileToECDSA` since these are just wrappers for eth crypto. And made a small fix on order of err check in `uploader.go`.
1 parent 841771e commit 70c8c5b

File tree

4 files changed

+7
-40
lines changed

4 files changed

+7
-40
lines changed

cmd/vaults/commands.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"crypto/ecdsa"
6+
"encoding/hex"
67
"encoding/json"
78
"errors"
89
"fmt"
@@ -625,7 +626,7 @@ func newSignCommand() *cli.Command {
625626
if err != nil {
626627
return fmt.Errorf("failed to sign file: %s", err)
627628
}
628-
signature := signing.SignatureBytesToHex(signatureBytes)
629+
signature := hex.EncodeToString(signatureBytes)
629630
fmt.Println(signature)
630631

631632
return nil

internal/app/uploader.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package app
33
import (
44
"context"
55
"crypto/ecdsa"
6+
"encoding/hex"
67
"fmt"
78
"io"
89
"os"
@@ -45,10 +46,10 @@ func (bu *VaultsUploader) Upload(
4546

4647
signer := signing.NewSigner(bu.privateKey)
4748
signatureBytes, err := signer.SignFile(filepath)
48-
signature := signing.SignatureBytesToHex(signatureBytes)
4949
if err != nil {
5050
return fmt.Errorf("signing the file: %s", err)
5151
}
52+
signature := hex.EncodeToString(signatureBytes)
5253

5354
filename := filepath
5455
if strings.Contains(filepath, "/") {

pkg/signing/signing.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package signing
33
import (
44
"bufio"
55
"crypto/ecdsa"
6-
"encoding/hex"
76
"fmt"
87
"io"
98
"os"
@@ -123,8 +122,3 @@ func (s *Signer) SignBytes(data []byte) ([]byte, error) {
123122

124123
return signature, nil
125124
}
126-
127-
// SignatureBytesToHex converts a byte slice to a hex-encoded string.
128-
func SignatureBytesToHex(b []byte) string {
129-
return hex.EncodeToString(b)
130-
}

pkg/signing/signing_test.go

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package signing
22

33
import (
44
"crypto/ecdsa"
5+
"encoding/hex"
56
"os"
67
"testing"
78

@@ -72,7 +73,7 @@ func TestSignFile(t *testing.T) {
7273
defer cleanup()
7374

7475
signatureBytes, err := signer.SignFile(filename)
75-
signature := SignatureBytesToHex(signatureBytes)
76+
signature := hex.EncodeToString(signatureBytes)
7677
if tc.wantErr != "" {
7778
require.Error(t, err, "Expected an error for %v", tc.name)
7879
require.Contains(t, err.Error(), tc.wantErr, "SignFile() error = %v, wantErr %v", err, tc.wantErr)
@@ -111,7 +112,7 @@ func TestSignBytes(t *testing.T) {
111112
for _, tc := range testCases {
112113
t.Run(tc.name, func(t *testing.T) {
113114
signatureBytes, err := signer.SignBytes(tc.content)
114-
signature := SignatureBytesToHex(signatureBytes)
115+
signature := hex.EncodeToString(signatureBytes)
115116
if tc.wantErr != "" {
116117
require.Error(t, err, "Expected an error for %v", tc.name)
117118
require.Contains(t, err.Error(), tc.wantErr, "SignBytes() error = %v, wantErr %v", err, tc.wantErr)
@@ -154,36 +155,6 @@ func TestPrivateKey(t *testing.T) {
154155
},
155156
wantErr: "",
156157
},
157-
{
158-
name: "should fail to load 0x prefixed string",
159-
setup: func() (pk string, filename string, cleanup func()) {
160-
pk = "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
161-
return pk, "", func() {}
162-
},
163-
wantErr: "invalid hex character 'x' in private key",
164-
},
165-
{
166-
name: "should fail to load random string",
167-
setup: func() (pk string, filename string, cleanup func()) {
168-
pk = "1234abcd"
169-
return pk, "", func() {}
170-
},
171-
wantErr: "invalid length, need 256 bits",
172-
},
173-
{
174-
name: "should fail to load empty private key file",
175-
setup: func() (pk string, filename string, cleanup func()) {
176-
tmpFile, _ := os.CreateTemp("", "test_file")
177-
name := tmpFile.Name()
178-
err := tmpFile.Close()
179-
require.NoError(t, err, "Error closing file")
180-
return pk, name, func() {
181-
err = os.Remove(name)
182-
require.NoError(t, err, "Error removing file")
183-
}
184-
},
185-
wantErr: "key file too short, want 64 hex characters",
186-
},
187158
}
188159

189160
for _, tc := range testCases {

0 commit comments

Comments
 (0)