Skip to content

Commit

Permalink
refactor(ecdsa/utils): use strings.TrimPrefix to trim 0x prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
samlaf committed Aug 8, 2024
1 parent 0d62354 commit 6ae0800
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions crypto/ecdsa/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/ethereum/go-ethereum/common"
gethcommon "github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -116,9 +117,7 @@ func GetAddressFromKeyStoreFile(keyStoreFile string) (gethcommon.Address, error)
}

func KeyAndAddressFromHexKey(hexkey string) (*ecdsa.PrivateKey, common.Address, error) {
if len(hexkey) > 2 && hexkey[:2] == "0x" {
hexkey = hexkey[2:]
}
hexkey = strings.TrimPrefix(hexkey, "0x")
ecdsaSk, err := crypto.HexToECDSA(hexkey)
if err != nil {
return nil, common.Address{}, fmt.Errorf("failed to convert hexkey %s to ecdsa key: %w", hexkey, err)
Expand Down

0 comments on commit 6ae0800

Please sign in to comment.